-
Notifications
You must be signed in to change notification settings - Fork 7
Configuration
Francesco Novy edited this page Nov 20, 2018
·
3 revisions
You can configure the l10n
service to your needs. These are the main configuration options available for you:
// apps/services/l10n.js
import L10n from 'ember-l10n/services/l10n';
import { computed } from '@ember/object';
export default L10n.extend({
availableLocales: computed(function() {
return {
en: 'English',
de: 'German - Deutsch'
};
}),
// If true, it will try to automatically set the language to the browser's language
// Set this to false if you want to manually set the language
autoInitialize: true
});
You can manually change the language of the service with these methods of the
l10n.setLocale('de'); // Set the locale - returns a promise
l10n.hasLocale('de'); // returns true or false
l10n.detectLocale(); // returns the best fitting locale for the browser
By default, ember-l10n assumes your locale files are fingerprinted in production environment.
This requires you to add this to ember-cli-build.js
:
// ember-cli-build.js
let env = process.env.EMBER_ENV || 'development';
let app = new EmberAddon(defaults, {
// ... other options...
fingerprint: {
enabled: env === 'production',
generateAssetMap: true,
fingerprintAssetMap: true,
// We need to add json to the fingerprinted extentions
extensions: ['js', 'css', 'png', 'jpg', 'gif', 'map', 'svg', 'json']
}
});
This uses ember-cli-ifa to get the asset map, in order to get the fingerprinted locale files.
If you want to completely turn off fingerprinting, add this to your config/environment.js
:
// config/environment.js
let ENV = {
ifa: { enabled: false }
};
It will then load the locales normally from e.g. /assets/locales/en.json
.