Conversation
To run test, use: docker-compose exec appwrite test /usr/src/code/tests/e2e/General/LocaleMissingTest.php
|
After working on the translations I found specific examples of these problems in the code. I think that Pluralization is still a needed feature. Dynamic values + PluralizationNot as problematic as I thought it would be. I don't think we will need this on more than 10 places in the whole appwrite console. Problem is that if a contributor sees
Nested translationsSo far, I have only seen this 3 or 4 times in total. I would even say this is less important than pluralization. This can be easily solved with the system of chunks we use currently: We can add one note into the translation tutorial on how these |
Dynamic valuesImplemented 🤩 PluralizationIgnored, for now, will be added in future.. Some time... Not this PR. Nested translationsIgnored, there are only +-5 use-cases, we will stick to |



What does this PR do?
This PR makes it possible to translate the whole Appwrite console into any language by taking texts from code into
jsonfile.Test Plan
To run test, do
docker-compose exec appwrite test /usr/src/code/tests/e2e/General/LocaleMissingTest.phpI prepared a test that checks for
->getText(with keys that are not presented inen.json. This check ignorescontinentsandcountriesbecause these are used with dynamic keys.For tests to work properly, we can' use variable names as a key.
If someone decides to write text directly into code without using
getText, this test won't catch that.Tests also won't spot when you define a translation in
en.jsonand don't use it anywhere in the code (most likely wrong CopyPaste, happened to me multiple times).Additionally, tests will log 20 most used values in
en.json. This helps you spot duplicates when refactoring a bigger part of the UI (for example, I used 18 keys for the value "Cancel").Connections with other branches
databasetranslationhometranslationuserstranslationIssues to discuss
This is a draft PR to start discussing issues about localization
1. Dynamic values
Problem:
English: The project has 3 collections taking 12 MB space and includes 512k files.
Solution:
English: The project has { collectionsAmount } collections taking { spaceUsage } space and includes { documentsAmount } files.
In code you would do something like:
2. Pluralization
Problem:
English: Meldiron ate 1 apple / Meldiron ate 2+ apples
Slovak: Meldiron zjedol 1 jablko / Meldiron zjedol 2/3/4 jablká / Meldiron zjedol 5+ jabĺk
Solution:
English: Meldiron ate { applesAmount } { applesAmount, PLURAL, =1 {apple} other {apples} }
Slovak: Meldiron zjedol { applesAmount } { applesAmount, PLURAL, =1 {jablko} few {jablká} other {jabĺk} }
Keywords:
=Xexact numberonealternative to=1few2, 3 or 4otheranything elseMore info: https://www.npmjs.com/package/messageformat
In code you would do something like:
3. Gender
Problem:
English: Meldiron is ready / Sara is ready
Slovak: Meldiron je pripravený / Sara je *pripravená
(verbs change depending on gender)
We ignore this one for now because we don't store gender
4. Nested translations
Problem:
How we would translate it:
Solution with dynamic values would not help... We would still have nested translations
Terms and ConditionsandPrivacy Policyinside a placeholder. We would go to 3 chunks from 4, but still not a solution.Solution:
Mark nested placeholders and write a logic to apply it.
How Localazy solves it:
_Arepresents<a>tag so developers can find it easier in the bigger block. This solution requires some library that would extract and inject the translation without breaking the HTML.. Not really sure how Localazy does it.How I would solve it:
and in code we could have something like:
(
{ $text }would be a reserved word; we follow the same pattern as pluralization solution)Author comments