How to deal with defaultLanguage
See original GitHub issueHi @GertjanReynaert, before going forward I wanted to say thank you for your work, great job!
I opened this issue since I’m a bit confused about how to deal with the defaultLanguage.
Let’s say you wrote all the message descriptors in your components and then used babel-plugin-react-intl to extract them to a directory, you google a while about how to join them and found this package, so you read the docs and create a script like this:
import manageTranslations from 'react-intl-translations-manager';
const defaultLanguage = 'en-US';
manageTranslations({
messagesDirectory: 'src/translations/extractedMessages',
translationsDirectory: 'src/translations/locales/',
languages: [defaultLanguage], // any language you need
});
you run the script and voila, everything worked as expected, but there is a file that grabs your attention: whitelist_en-US.json, so you read the docs again and found this:
languages (optional, default: []) What languages the translation manager needs to maintain. Specifying no languages actually doesn’t make sense, but won’t break the translationManager either. example: for [‘nl’, ‘fr’] the translation manager will maintain a nl.json, fr.json, whitelist_nl.json and a whitelist_fr.json file
You think: “I can have more control with this feature, great!”
And then you modify some defaultMessage, run the script again, and you get:
So you are stuck, you was expecting the generated json to update with the latest change you’ve introduced but instead you got all this…
So the question would be:
Shouldn’t it work like I’m expecting or if not, why?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
First: thx for using this package!
Second: sorry for the confusion around the default language!
I haven’t found a good way to deal with the defaultLanguage yet, but ATM, it’s not really recommended to include the defaultLanguage in your languages array. At the start of this package I approached it like this: since your defaultMessages are in your defaultLanguage, you don’t need to manage them, so you don’t need to include the language in the array of languages to be managed.
That being said, we should come up with an approach to help people out (either a way to include the default language, or better docs) since this is a frequently returning question.
First of all thanks for the tool @GertjanReynaert Im using it and its amzazing. Im also having questions regarding this feature.
I have it included because I want it to generate the ‘en.json’ file from my messages, but I don’t like to get that output.
Maybe we should be able to define a defaultLanguage, the manager will then generate the defaultMessages .json with that name but ignore it when comparing files?
That way we get the file generation and nice translations management. just an idea!