-
Notifications
You must be signed in to change notification settings - Fork 167
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
Implementing new CLDR extracting #68
Changes from all commits
6c79b0a
778e2e4
d8fdfd5
d9a4707
0d6d68d
af8b363
f248362
f49f89a
420351c
d7a0d8f
edc8d45
0145bba
23f762a
5cd2fb8
cf2723f
0b80517
4fa63d6
b1f3dc2
addc0c5
f1701a1
72a9243
925e0b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Ember from 'ember'; | ||
|
||
function notImplemented () { | ||
throw new Error('not implemented'); | ||
} | ||
|
||
export default Ember.Object.extend({ | ||
findLanguage: notImplemented, | ||
findTranslation: notImplemented | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function IntlGetResult (translation, locale) { | ||
this.translation = translation; | ||
this.locale = locale; | ||
} | ||
|
||
export default IntlGetResult; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Ember from 'ember'; | ||
import IntlGetResult from 'ember-intl/models/intl-get-result'; | ||
import Locale from 'ember-intl/models/locale'; | ||
import IntlAdapter from 'ember-intl/adapter'; | ||
|
||
function normalize (fullName) { | ||
Ember.assert('Lookup name must be a string', typeof fullName === 'string'); | ||
|
||
return fullName.toLowerCase(); | ||
} | ||
|
||
export default IntlAdapter.extend({ | ||
findLanguage: function (locale) { | ||
if (locale instanceof Locale) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this is too much abstraction for data that can be represented as a hash. But this might need to stay for back-compat? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return locale; | ||
} | ||
|
||
if (typeof locale === 'string') { | ||
return this.container.lookup('locale:' + normalize(locale)); | ||
} | ||
}, | ||
|
||
findTranslation: function (locales, translationKey) { | ||
var container = this.container; | ||
var locale, translation, key; | ||
|
||
for (var i=0, len = locales.length; i < len; i++) { | ||
key = locales[i]; | ||
locale = this.findLanguage(key); | ||
|
||
if (locale) { | ||
translation = locale.getValue(translationKey); | ||
|
||
if (typeof translation !== 'undefined') { | ||
return new IntlGetResult(translation, key); | ||
} | ||
} | ||
} | ||
} | ||
}); |
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.
Not documenting this yet, but it will eventually be exposed for those people who want to specify their own way of loading translations. The CLDR portion of this hasn't been thought out yet, but it will ideally be another hook off this.
See: #69