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
Internationalization (i18n) with react-i18next #921
Conversation
import i18n from 'i18next'; | ||
import { reactI18nextModule } from 'react-i18next'; | ||
import * as translationEN from '../../../../public/locales/en/translation'; | ||
import * as translationCS from '../../../../public/locales/cs/translation'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably better off starting with some ISO standard codes; perhaps the same as we use for profile languages? (ISO 639 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's use the ISO 639-2 instead of 639-1. It includes more languages and we already use it as @simison describe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh bummer, I think I've looked up something wrong here.
I picked the ISO standard from this sentence:
The
languages.json
is a custom made file which contains languages fromlanguages_orig.json
that hasiso_639_2
standard defined.
But it just states that we pick only those languages from the whole massive list and then actually in the database we use codes like fi_FI
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to revert to ISO_639-1, then? It should be as easy as dropping a commit.
Actually, ISO_639-1 will be compatible with moment.locale()
, i18next documentation etc.
And when we need to use languages out of the scope of ISO_639-1, we can use ISO_639-3 just for them.
I would prefer not to use fi_FI
format though - not a standard, redundant information and hard to reuse in localization library configs without custom parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable 👍 I'll leave it up to you to decide since you have better insight. :-) We can very easily refactor at any point if we hit issues. That said, probably easier to get it right from the beginning.
Do ISO_639-1 or ISO_639-2 make difference between localized languages, such as English GB/US or French CA/FR etc? In volunteering space those are often pretty fast to crop up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I made some false assumptions (i.e. fi_FI
is not a redundant information). I'll research more.
What do you think if we instead use const Volunteering = () => {
return <Something />;
}
export default withNamespaces()(Volunteering); That way if function/component is returning multiple times, we wouldn't need to wrap each return with export default const Volunteering = () => {
if (something) {
return (
<NamespacesConsumer>
<Something />
</NamespacesConsumer>
);
}
return (
<NamespacesConsumer>
<Something />
</NamespacesConsumer>
);
} |
It's nice, yes. There is just a check in the code for importing react components to angular, which is failing with this. It could be possible to drop that check, too. Update: |
It's very important that we figure out what localization tool we can use. (A tool that non-programmers can use to translate the files in It makes a difference between choosing this library and not. Thank you @Akronix for pointing this out to me. |
79e1a29
to
bd129a9
Compare
Good point! I don't see us being limited to anything specific, because i18n-next has utils for to/from Gettext and other formats as well even a Gettext Webpack loader: https://www.i18next.com/overview/plugins-and-utils#utils Gettext is about as free and open as you can get so we can either use self-hosted software, SAAS software to even local tools such as Poedit. i18n-next seems great also because it has support for such a variety of frameworks, among others Express.js ( |
092d597
to
1ec88fc
Compare
Seems |
A design of language switch button would be nice. |
For non-authenticated users, it could always be visible in the header. We can get quickly going with a simple Bootstrap navigation dropdown: It should fit also in mobile header nicely: (and if it doesn't, using a shortening "FI" for Finnish etc should work. We'll hit some limits with this when we add more languages but we can work more on it then. I have some old designs from BeWelcome hackathon/early Trustroots times that should be useful. Technically I like the idea of using a For authenticated users, we don't need to show it all the time (as they really need to change it just once). Instead, we can add it to their "account" page as
Probably good to hide these selections behind a feature flag until we have something to show? Thoughts? @mrkvon What were you thinking specifically when asking "How should it behave"? |
@simison You answered precisely what I was asking. Thank you! |
We can save the preferred language in a client (set a cookie) or in a database ( |
Cookie sounds good to me as a starting point since that's what unregistered users need. For authenticated users, we can store it in their user table just like any other account content.
Totally 👍 |
41422fa
to
73cc764
Compare
Wants to be merged. Somebody should succeed with using the tools for extracting translations, and tools for translating. I'll try tomorrow. |
@guaka Also we should decide whether we want to use natural, or keybased catalog. Currently we use natural one (translation keys equal English values). The i18next-gettext-converter would be nice to have plugged to make many translation tools available. And other plugins. |
I'd go for natural like it's now — it removes some mental complexity while developing and moves the overhead of "changing strings" to translation work instead. I think that's fine since we aren't changing strings that often.
Code is looking good 👍 just need to give this a spin (aiming to do that tonight). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great and tests well!
Let's just hide the <select>
in the header for now from all environments (just via feature flag) before merging so that master
won't feel broken even in the development environment.
There will be quite a few tasks as a follow-up but we can work on this incrementally.
Nice job handling this; 🚢 it!
Opened an issue for |
change variable name
79f2e3d
to
3eb291a
Compare
Ok, let's make a leap of trust that the localization tools will work. |
As long as things are behind a feature flag and not breaking anything or making the build enormous, we're safe to iterate and refactor. 👍 |
What about already enabling the language switcher for users with the "beta" role? |
Proposed Changes
Largely following tutorials on https://react.i18next.com.
Testing Instructions
git checkout react-i18next
npm install
npm start
eng
tocze
and observe the magicFixes #492
TODO: