chore: update l10n scripts for country code (#970)

This commit is contained in:
Diego Beraldin 2024-06-11 14:13:10 +02:00 committed by GitHub
parent 49b894fed9
commit d7ac02101b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 77 additions and 48 deletions

View File

@ -152,8 +152,11 @@ In this case, you should:
### 3.4 Add a new localization ### 3.4 Add a new localization
The preferred way for localizations (l10ns) is to submit a pull request (PR) as detailed in > [!NOTE]
the [next section](#35-submit-a-pull-request). > This section explains how translation are managed in the app (creating a new implementation of the
> Strings interface, modify the bottom sheet to allow selecting it etc.) and it is useful to
> understand the global mechanism. However, translators are encouraged to review the messages on
> Weblate and leave all the heavy-lifting work to project maintainers.
The project uses The project uses
the [Lyricist](https://github.com/adrielcafe/lyricist) library for internationalization, which the [Lyricist](https://github.com/adrielcafe/lyricist) library for internationalization, which
@ -177,10 +180,10 @@ anonymous implementation of `Strings` stored in a variable called `XxYyStrings`
```kotlin ```kotlin
internal val XxYyStrings = internal val XxYyStrings =
object : Strings { object : Strings {
override val actionBackToTop = "..." override val actionBackToTop = "..."
// ... continue overriding all the remaining properties // ... continue overriding all the remaining properties
} }
``` ```
It is recommended to copy the contents of the existing `EnStrings.kt` (i.e. the base localization) It is recommended to copy the contents of the existing `EnStrings.kt` (i.e. the base localization)
@ -193,15 +196,15 @@ Afterwards, edit the `Strings.kt` file in the same directory with the following
```kotlin ```kotlin
object Locales { object Locales {
// ... // ...
const val XX_YY = "xx_YY" const val XX_YY = "xx_YY"
} }
internal val localizableStrings: Map<LanguageTag, Strings> = internal val localizableStrings: Map<LanguageTag, Strings> =
mapOf( mapOf(
// ... // ...
Locales.XX_YY to XxYyStrings, Locales.XX_YY to XxYyStrings,
) )
``` ```
Finally, if you want you can change the rest of the code (e.g. the language dialog, etc) please do Finally, if you want you can change the rest of the code (e.g. the language dialog, etc) please do

View File

@ -86,7 +86,8 @@ for some technical notes.
- multi-community (community aggregation); - multi-community (community aggregation);
- view the moderation log; - view the moderation log;
- community moderation tool (examine and resolve reports, ban users, feature posts, block - community moderation tool (examine and resolve reports, ban users, feature posts, block
further comments from posts, mark comments as distinguished, remove posts/comments, examine all posts/comments created further comments from posts, mark comments as distinguished, remove posts/comments, examine all
posts/comments created
in your communities); in your communities);
- save posts and comments you are creating as drafts to edit them later; - save posts and comments you are creating as drafts to edit them later;
@ -94,31 +95,42 @@ Most clients for Lemmy currently offer the first points (with various degrees of
there is nothing special about Raccoon, whereas the last ones are less common and are directed to there is nothing special about Raccoon, whereas the last ones are less common and are directed to
more demanding users. more demanding users.
Concerning customization, the ability to change some aspects like font face or size and app colors, vote format, bar Concerning customization, the ability to change some aspects like font face or size and app colors,
transparency and so on was of paramount importance from the very beginning. Similarly, users should be able to use the vote format, bar
transparency and so on was of paramount importance from the very beginning. Similarly, users should
be able to use the
app in their native language and change the UI language independently of the system language. app in their native language and change the UI language independently of the system language.
This app is also intended for moderators who want to use their mobile device, offering moderation tools (feature post, This app is also intended for moderators who want to use their mobile device, offering moderation
lock post, distinguish comment, remove post/comment, ban users) and the ability to revert any of these actions. tools (feature post,
lock post, distinguish comment, remove post/comment, ban users) and the ability to revert any of
these actions.
The project is under active development, so expect new features to be added over time. Have a look on the issues labeled The project is under active development, so expect new features to be added over time. Have a look
on the issues labeled
with "feature" in the issue tracker to get an idea of what's going to come next. with "feature" in the issue tracker to get an idea of what's going to come next.
If you have ideas, feedback, suggestions or comments remember to speak up and use your voice. You can add reports or If you have ideas, feedback, suggestions or comments remember to speak up and use your voice. You
can add reports or
request features and they will be considered. request features and they will be considered.
## Why was the project started? ## Why was the project started?
Because raccoons are so adorable, aren't they? 🦝🦝🦝 Because raccoons are so adorable, aren't they? 🦝🦝🦝
Joking apart, one of the main goals was to experiment with KMP and learn how to properly deal with the challenges of a Joking apart, one of the main goals was to experiment with KMP and learn how to properly deal with
multiplatform environment, and a medium-sized project like this was an ideal testing ground for that technology. the challenges of a
multiplatform environment, and a medium-sized project like this was an ideal testing ground for that
technology.
Secondly, I felt that the Android ecosystem of Lemmy apps was a little "poor" with few native apps (fewer open source), Secondly, I felt that the Android ecosystem of Lemmy apps was a little "poor" with few native apps (
while the "market" is dominated by iOS and cross-platform clients. I ❤️ Kotlin, I ❤️ Free and Open Source Software and fewer open source),
while the "market" is dominated by iOS and cross-platform clients. I ❤️ Kotlin, I ❤️ Free and Open
Source Software and
I ❤️ native app development, so there was a niche that could be filled. I ❤️ native app development, so there was a niche that could be filled.
Developing a new client was an opportunity to add all the good features that were "scattered" across different apps, Developing a new client was an opportunity to add all the good features that were "scattered" across
different apps,
e.g. the feature richness of [Liftoff](https://github.com/liftoff-app/liftoff), the e.g. the feature richness of [Liftoff](https://github.com/liftoff-app/liftoff), the
multi-community feature of multi-community feature of
[Summit](https://github.com/idunnololz/summit-for-lemmy) and the polished UI of the really great [Summit](https://github.com/idunnololz/summit-for-lemmy) and the polished UI of the really great
@ -126,10 +138,13 @@ multi-community feature of
enough to make users feel "at home" and choose what they want, while at the same time having a not enough to make users feel "at home" and choose what they want, while at the same time having a not
too cluttered interface (except for the Settings screen - I know!) too cluttered interface (except for the Settings screen - I know!)
In the third place, this app has been a means to dig deeper inside Lemmy's internals and become more humble and patient In the third place, this app has been a means to dig deeper inside Lemmy's internals and become more
towards other apps because there are technical difficulties in having to deal with a platform like Lemmy. humble and patient
towards other apps because there are technical difficulties in having to deal with a platform like
Lemmy.
This involves a high level of discretion and personal taste, I know, but this project _is_ all about experimenting and This involves a high level of discretion and personal taste, I know, but this project _is_ all about
experimenting and
learning. learning.
## Technical notes: ## Technical notes:
@ -138,12 +153,16 @@ The project uses the following technologies:
- [Koin](https://github.com/InsertKoinIO/koin) for dependency injection - [Koin](https://github.com/InsertKoinIO/koin) for dependency injection
- [Voyager](https://github.com/adrielcafe/voyager) for screen navigation - [Voyager](https://github.com/adrielcafe/voyager) for screen navigation
- [Ktor](https://github.com/ktorio/ktor) and [Ktorfit](https://github.com/Foso/Ktorfit) for networking - [Ktor](https://github.com/ktorio/ktor) and [Ktorfit](https://github.com/Foso/Ktorfit) for
networking
- [Lyricist](https://github.com/adrielcafe/lyricist) for l10n - [Lyricist](https://github.com/adrielcafe/lyricist) for l10n
- [Multiplatform settings](https://github.com/russhwolf/multiplatform-settings) for encrypted preferences - [Multiplatform settings](https://github.com/russhwolf/multiplatform-settings) for encrypted
- [SQLDelight](https://github.com/cashapp/sqldelight) and [SQLCipher](https://github.com/sqlcipher/sqlcipher) for local preferences
- [SQLDelight](https://github.com/cashapp/sqldelight)
and [SQLCipher](https://github.com/sqlcipher/sqlcipher) for local
persistence persistence
- [Multiplatform Markdown Renderer](https://github.com/mikepenz/multiplatform-markdown-renderer) for Markdown - [Multiplatform Markdown Renderer](https://github.com/mikepenz/multiplatform-markdown-renderer) for
Markdown
rendering rendering
More info about the technologies used in the project can be found in More info about the technologies used in the project can be found in
@ -157,11 +176,12 @@ the [CONTRIBUTING.md](https://github.com/diegoberaldin/RaccoonForLemmy/blob/mast
- create a post on the project's [community](https://lemmy.world/c/raccoonforlemmy) on - create a post on the project's [community](https://lemmy.world/c/raccoonforlemmy) on
Lemmy.world for broader questions, opinions, personal feedback, suggestions, insults or whatever Lemmy.world for broader questions, opinions, personal feedback, suggestions, insults or whatever
you feel like writing you feel like writing
- if you are a translator and want to help out with l10n or submit some corrections but you don't - if you are a translator and want to help out with l10n or submit some corrections, check out the
feel confident with repository forks, pull requests, managing resource files, etc. feel free to project [on Weblate](https://hosted.weblate.org/projects/raccoonforlemmy/), so you can review the
drop an email or contact me in any way. existing messages or add missing ones.
Please remember: every contribution is welcome and everyone's opinion matters here. This is a community project, open Please remember: every contribution is welcome and everyone's opinion matters here. This is a
community project, open
source, ad-free and free of charge, and it belongs to us all so don't be afraid to get involved. source, ad-free and free of charge, and it belongs to us all so don't be afraid to get involved.
And don't forget every 🦝's motto: «Live Fast, Eat Trash» (abbreviated L.F.E.T.). And don't forget every 🦝's motto: «Live Fast, Eat Trash» (abbreviated L.F.E.T.).

View File

@ -47,11 +47,14 @@ def convert(input_path, output_path):
def main(): def main():
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("Usage: {0} lang".format(sys.argv[0])) print("Usage: {0} lang_code country_code".format(sys.argv[0]))
return return
lang = sys.argv[1] lang_code = sys.argv[1]
source_file = "../core/l10n/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/l10n/messages/{0}Strings.kt".format(lang.capitalize()) country_code = ""
dest_file = "../l10n/strings_{0}.xml".format(lang) if len(sys.argv) > 2:
country_code = sys.argv[2]
source_file = "../core/l10n/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/l10n/messages/{0}{1}Strings.kt".format(lang_code.capitalize(), country_code.capitalize())
dest_file = "../l10n/strings_{0}{1}.xml".format(lang_code, country_code)
if not os.path.isdir("../l10n"): if not os.path.isdir("../l10n"):
os.mkdir("../l10n") os.mkdir("../l10n")
convert(source_file, dest_file) convert(source_file, dest_file)

View File

@ -15,28 +15,31 @@ def read_l10n_from_file(input_path):
res.append({"key": k, "value": v}) res.append({"key": k, "value": v})
return res return res
def write_l10n_to_file(lang, messages, output_path): def write_l10n_to_file(lang_code, country_code, messages, output_path):
with open(output_path, "w") as file_handle: with open(output_path, "w") as file_handle:
file_handle.write("package com.github.diegoberaldin.raccoonforlemmy.core.l10n.messages\n") file_handle.write("package com.github.diegoberaldin.raccoonforlemmy.core.l10n.messages\n")
file_handle.write("\n") file_handle.write("\n")
file_handle.write("internal val {0}Strings =\n".format(lang.capitalize())) file_handle.write("internal val {0}{1}Strings =\n".format(lang_code.capitalize(), country_code.capitalize()))
file_handle.write(" object : Strings {\n") file_handle.write(" object : Strings {\n")
for pair in messages: for pair in messages:
file_handle.write(" override val {0} = \"{1}\"\n".format(pair["key"], pair["value"])) file_handle.write(" override val {0} = \"{1}\"\n".format(pair["key"], pair["value"]))
file_handle.write(" }\n") file_handle.write(" }\n")
def convert(lang, input_path, output_path): def convert(lang_code, country_code, input_path, output_path):
messages = read_l10n_from_file(input_path) messages = read_l10n_from_file(input_path)
write_l10n_to_file(lang, messages, output_path) write_l10n_to_file(lang_code, country_code, messages, output_path)
def main(): def main():
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("Usage: {0} lang".format(sys.argv[0])) print("Usage: {0} lang_code country_code".format(sys.argv[0]))
return return
lang = sys.argv[1] lang_code = sys.argv[1]
source_file = "../l10n/strings_{0}.xml".format(lang) country_code = ""
dest_file = "../core/l10n/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/l10n/messages/{0}Strings.kt".format(lang.capitalize()) if len(sys.argv) > 2:
convert(lang, source_file, dest_file) country_code = sys.argv[2]
source_file = "../l10n/strings_{0}{1}.xml".format(lang_code, country_code)
dest_file = "../core/l10n/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/l10n/messages/{0}{1}Strings.kt".format(lang_code.capitalize(), country_code.capitalize())
convert(lang_code, country_code, source_file, dest_file)
if __name__ == "__main__": if __name__ == "__main__":
main() main()