-
Notifications
You must be signed in to change notification settings - Fork 183
[Feature] Allow to pass an array of fallback translations #230
Conversation
We mark missing translations with |
@@ -19,8 +19,20 @@ export default Ember.Object.extend(Ember.Evented, { | |||
t: function(key, data = {}) { | |||
const locale = this.get('_locale'); | |||
Ember.assert("I18n: Cannot translate when locale is null", locale); | |||
const fallbacks = get(data, 'fallbacks'); |
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.
The logic below will be a little cleaner if you do
const fallbacks = getWithDefault(data, 'fallbacks', []);
@jamesarosen Mixin the main key with the fallbacks in a single array and let The point am not 100% convinced yet is the fallbacks being specified as a |
7d073e0
to
2f75ba7
Compare
77352c9
to
f35462f
Compare
Updated this PR to almost mimic 1:1 rails-i18n behaviour (see http://guides.rubyonrails.org/i18n.html#defaults) The array of fallbacks is received in the options hash and the name of the key with the fallback translations is named Examples:
|
Tests are failing because of the glimmer incompatibility. |
…er_to_readme Explain that you can't translate until `ember-i18n` initializer runs
You can either rebase off master now that the beta and canary tests are marked as may-fail, or wait until emberjs/ember.js#11445 and then #227 are merged. |
f35462f
to
47a97d8
Compare
47a97d8
to
2825423
Compare
Green 😁 |
Now that 4.0 is out of the door, can we revisit this? |
} | ||
|
||
Ember.assert(`Template for ${key} in ${this.id} is not a function`, Ember.typeOf(result) === 'function'); | ||
Ember.assert(`Template for ${fallbackChain[0]} in ${this.id} is not a function`, Ember.typeOf(result) === 'function'); |
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.
This might be confusing, since it could be one of the fallbacks that's wrong. I'm wondering whether we should save off the key of the translation we found so we can use it here.
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.
Done
I'm 100% sold on the idea and the API! I made a couple comments about smaller details. |
Decission: Receive the fallbacks as an option in the `data` object or is the key itself the one than can be an array
Also, default can be either an array or a string
2825423
to
44d76f3
Compare
Feedback applied. |
} | ||
|
||
Ember.assert(`Template for ${key} in ${this.id} is not a function`, Ember.typeOf(result) === 'function'); | ||
Ember.assert(`Template for ${fallbackChain[i]} in ${this.id} is not a function`, Ember.typeOf(result) === 'function'); |
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.
This should be 0
, not i
, right?
No, I'm wrong. This is the found version.
+1 merging and squashing... |
Closed in 8aa758c |
wohoo! |
I'd like to document this in the wiki, but I'm not sure of a good spot. Maybe at the bottom of Translating Text in a new "Fallback Translation Keys" section? |
Yes, that seems a good place. That section basically teaches all the usages of the library. |
I'm need to create a helper that translates error messages following the same conventions that rails-i18n uses for translate error messages in active record.
For those not familiar with rails-i18n, the fallback chain that it uses is like this (being
Admin
a subclass ofUser
)While this is specific of my in progress meta-addon (addon built on top of ember-i18n 💥 ), the ability of having fallback translations is a must for me and I think general purpose feature.
ATM i need to compare if the returned string matches the regular expression
/Missing translation/
or alternatively use the private APIi18n._locale
.The downside of this change is that
fallbacks
becomes keyword-ish. I'm open to other ideas about how to implement this.