Skip to content

Commit 31ad0d8

Browse files
committed
Rough mechanism for identifying whether a locale is RTL
Gotchas: 1. Locale name must match directly (the lookup function doesn't fall back to parent locale if subtags are provided) 2. (big) The RTL-containing locale must have a config file manually provided; this doesn't look up the base locales provided in the ember-i18n addon Next: add error handling if things are blank [#LEI-348]
1 parent dac377b commit 31ad0d8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

app/controllers/participate.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Ember from 'ember';
2+
3+
export default Ember.Controller.extend({
4+
i18n: Ember.inject.service(),
5+
6+
// Set by login page
7+
locale: null,
8+
9+
rtl: Ember.computed('i18n.locale', function() {
10+
// Big assumption: any RTL locale we include MUST define the config manually! (can't seem to load the ember-18n config)
11+
12+
const locale = this.get('i18n.locale');
13+
// TODO undefined check
14+
const baseLocale = locale.split('-')[0];
15+
// Ember i18n service doesn't expose config directly, so we fetch it in a manner analogous to `addTranslations`
16+
// https://github.com/jamesarosen/ember-i18n/issues/375
17+
// https://github.com/jamesarosen/ember-i18n/blob/a98bdaecebb0cddfa30ef98aacc032f38ac50ae5/addon/utils/add-translations.js#L6
18+
const key = `locale:${baseLocale}/config`; // TODO: check base translation code- this only works if locales explicitly define a config
19+
const config = Ember.getOwner(this)._lookupFactory(key);
20+
console.log('Found config!', config, config.rtl);
21+
return config.rtl;
22+
}),
23+
24+
init() {
25+
// Services are lazily evaluated; make sure we can observe locale
26+
this.get('i18n');
27+
}
28+
});

app/locales/he/config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Ember-I18n includes configuration for common locales. Most users
2+
// can safely delete this file. Use it if you need to override behavior
3+
// for a locale or define behavior for a locale that Ember-I18n
4+
// doesn't know about.
5+
export default {
6+
rtl: true,
7+
//
8+
// pluralForm: function(count) {
9+
// if (count === 0) { return 'zero'; }
10+
// if (count === 1) { return 'one'; }
11+
// if (count === 2) { return 'two'; }
12+
// if (count < 5) { return 'few'; }
13+
// if (count >= 5) { return 'many'; }
14+
// return 'other';
15+
// }
16+
};

0 commit comments

Comments
 (0)