If you haven’t already, check out our contributing guidelines for onboarding!
We are implementing the structure for internationalisation and localisation.
As part of that, we need to implement a library to get texts. We will pass it a translation key, a locale and optionally an object with variables and it will return the correct text to use.
Let’s first add some clarity on what each language file will look like. By default, we will only have the en file (which will be the one used by default when no translation is found). Let’s use the file src/languages/en.js as an example, it would look something like this and would just export that object:
{
localizationConfig: {
phoneCountryCode: ‘1’,
}
signOut: “Sign Out”,
chatSwitcher: {
searchInput: “Find or start a chat”
}
IOUReport: {
oweRow: ({payerName, payeeName, amount, currency}) => `${payerName} owes` + currency(‘en’, amount, currency, 2) + `to ${payeeName}`;
}
}
There will be a main language file called translations.js, which will import each of the existing defined language files into one big object and export that. This is what will be used by the library to get the texts.
This library will only export one method translate(locale, key,variables = {}) and it will:
- Lookup that key in the translations object:
- Try to find it using the full locale
- Try to find it using the language part of the locale only (ie: the first part of the locale. For
es-ES will get es)
- If the language requested is not
en, then log an alert to the server (so we know we are missing a translation) and then try to find it using the default language en.
- In dev throw if the key does not exist and in production would use the key name and log an alert to the server.
- So now we found the key and see the value, if it is a string, it will return it as is. If the value is a function, it will call the function, passing the variables to it as a parameter (JS-Lib’s
Str.result does this)
Please include JUnit tests for the added methods.
Apply on Upwork: https://www.upwork.com/jobs/~019d8c473a29e6f464
https://github.com/Expensify/Expensify/issues/151944
If you haven’t already, check out our contributing guidelines for onboarding!
We are implementing the structure for internationalisation and localisation.
As part of that, we need to implement a library to get texts. We will pass it a translation key, a locale and optionally an object with variables and it will return the correct text to use.
Let’s first add some clarity on what each language file will look like. By default, we will only have the
enfile (which will be the one used by default when no translation is found). Let’s use the filesrc/languages/en.jsas an example, it would look something like this and would just export that object:There will be a main language file called
translations.js, which will import each of the existing defined language files into one big object and export that. This is what will be used by the library to get the texts.This library will only export one method
translate(locale, key,variables = {})and it will:es-ESwill getes)en, then log an alert to the server (so we know we are missing a translation) and then try to find it using the default languageen.Str.resultdoes this)Please include JUnit tests for the added methods.
Apply on Upwork: https://www.upwork.com/jobs/~019d8c473a29e6f464
https://github.com/Expensify/Expensify/issues/151944