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
Add support for nested translation keys in i18n #124
Add support for nested translation keys in i18n #124
Conversation
@ain this should probably get some tests before we consider merging. |
@jonschlinkert I actually migrated this logic form PHP where I used it for a YAML-based translation engine, also key-based. And I pushed it to our production already. Writing tests is a brilliant idea and should definitely be done. I'll try to find some time and update the i18n tests too, probably next week. |
This code changes loses the error when a string is not present. Is this on purpose? We would definitely want the build to fail if a string is missing. |
@LaurentGoderre the scenario is, you don't always want to fail a build if key is missing. Also, if key is empty deliberately, it shouldn't fail. I'd propose bringing back the error, but making it possible with an additional parameter to suppress errors and provide empty string if the key is missing, e.g. Additionally, maybe it's too much into i18n module's scope, but there are also scenarios in which you'd like to know if the key exists. Returning {{#if (i18n "key")}}
// standard behaviour
{{else}}
// exceptional behaviour
{{#endif}} So maybe it's even a good idea to go with |
I like the addition of finding the value based on the parts of the key.
{{i18n "foo" language="en_US"}}
{{i18n "foo" language="en_US" default="bar"}} If After these changes, I have an idea on how to make it work when the helper is nested too. |
why not just make this less verbose: For options like options: {
i18n: {
suppressFlag: false
}
} |
I like @doowb's suggestion, it's the best one, any objections? |
That's why they're called handlebars 😉 I like the combination of both. I was thinking of the global options too, but was going to add it as a second step. Also, I agree with @jonschlinkert that we need to make sure to have some tests around this. |
👍 |
closing since this lib has been refactored extensively |
Resolves #122 and assemble/grunt-assemble-i18n#12