-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
i18n for console and FES messages #3488
Conversation
@michelefenu thanks so much for opening this PR (and welcome to the p5js repo 💖)! I'm super excited to see some thinking and work around this topic. Will take a look this weekend and see if I have any thoughts! |
@outofambit thanks for the welcome! I await for your comments :) I left things like pluralization out of this implementation to keep things simple, but if the overall structure is fine I can add them in the future. |
Overall looks like a good start to me. A few minor points:
Also consider using |
|
IMHO better to use the named function declaration syntax |
Yeah then a more descriptive name would be preferred for clarity in the codebase
I didn't mean your implementation is messy, just that dealing with natural languages in code is always gonna be messy. 😄 |
@michelefenu looks like @limzykenneth already provided some feedback 🎉 (i'm on board for everything discussed above) |
I'm working on these improvements in a separate branch. I'm super busy these days but I plan to merge to my master branch very soon :) |
hey @ermenauta i'm going to close this pull request since its been a while, but feel free to reopen it whenever you're ready to look at this again! ping me if you have any questions :) thanks! |
This PR aims to provide a simple architecture proposal to internationalize console errors and FES messages. In reference to #3384 and #3390.
Language files are stored in src/core/i18n/ as json key/value entries. The language is selected at runtime, depending on the user browser language. If the user language is not supported (there is no dictionary for the language), then the english language file will be used.
{ "HELLO": "Hello World!!!", "HELLO_NAME": "Hello {0}!!!" }
Usage
Import the module
var i18n = require('./i18n/locales');
The simplest scenario:
console.log(i18n.__('HELLO')); // Hello World!!!
For parametric strings we need to pass the array of values as second parameter of the function:
console.log(i18n.__('HELLO_NAME', ['p5.js'])); // Hello p5.js!!!
A fallback system act as follows:
Note: this is my first contribution, all kind of feedback is welcome :)