-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement library to get texts #1844
Comments
Hi @arielgreen, I would like to work on this issue. Here is my proposal:
|
Proposal
en:{
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}`;
}
},
`other-locale`: {
...same set of keys but in the current locale.
}
...so on
Questions
|
@tugbadogan great question! The key should be either a string like @tugbadogan also, keep in mind this, which I don't see in your proposal:
@parasharrajat, no, that will be handled at a higher level, this library is not tasked to detect the browser's locale. |
For missing translations for given language, I'm going to do the following to handle that scenario (4th item in my proposal). 4. In translate method, I'm going to extract corresponding language object from translations object. If full locale or first part of the locale is not found in the translations object, I will log an alert to the server like this:
And missing translations for given key, I'm going to do the following (6th item in my proposal). 6. If key is found in translation object and the value is string, I will return the string. If it's a function I will call that function with given variables. If key is not found, I will return the key itself and log an alert to the server. Am I missing something here? |
Not sure we are saying the same thing or not 😅 There's 2 scenarios:
This is to fallback to english if someone requests a text in for example spanish that the spanish transalation does not have. That will let us know that we missed translating a key to spanish.
This comes after the previous check and it applies only to english (or when we are falling back to english). This has 2 goals:
I'll give you a an example which might be easier: I ask for key
I ask for key
|
Thanks for explanation @iwiznia. I got it now 👍 Is there a common way to distinguish dev from prod in the code? |
Yes, you can use this |
Regarding bundling and loading all the supported languagesThis will add some maintenance limitations:
As the app grows these factors will increase proportionally Instead I can offer you a solution where your translations are provided dynamically from you backend. You will be free to update or add more translations at any time without having to re-submit the app to the store Currently proposed structure for translation mappings is not optimalIOUReport: {
oweRow: ({payerName, payeeName, amount, currency}) => `${payerName} owes` + currency(‘en’, amount, currency, 2) + `to ${payeeName}`;
} This couples implementation details - how specific parameters work (currency). Instead You can use {
"IOUReport": {
"oweRow": "{payerName} owes {amount} to {payeeName}"
}
} Functionality like Sample translate() interface/usagetranslate('IOUReport.oweRow', {
payerName, // currency('en', amount, currency, 2)
amount: (localCtx) => formatCurrency(localeCtx.locale, amount, currency, 2),
payeeName,
}) When a param in params to A related topic in date internationalization: #1856 (comment) You can contact me for more details. |
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 filesrc/languages/en.js
as 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-ES
will 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.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
The text was updated successfully, but these errors were encountered: