This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {LocaleProvider} from './localeProvider.mjs'; | |
| ... | |
| const locale = new LocaleProvider(detectLocale()); | |
| locale.onChangeLocale((tag)=> console.log('Locale Changed to', tag)); | |
| console.log('Detected user locale is', detectLocale()); | |
| locale.setCurrent('el'); | |
| console.log('Current user locale is', locale.getCurrent()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import EventEmitter from 'https://unpkg.com/[email protected]/src/index.js?module'; | |
| export class LocaleProvider { | |
| constructor(currentLocale = 'en', availableLocales = ['en', 'el'], defaultLocale = 'en') { | |
| this.availableLocales = availableLocales; | |
| this.defaultLocale = defaultLocale; | |
| this.emiter = new EventEmitter(); | |
| this.setCurrent(currentLocale); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {detectLocale} from './utils.mjs'; | |
| ... | |
| console.log('Detected user locale is ', detectLocale()); // 'en' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function detectLocale() { | |
| const languageString = navigator.language || ''; | |
| const language = languageString.split(/[_-]/)[0].toLowerCase(); | |
| switch (language) { | |
| case 'en': | |
| return 'en'; | |
| case 'el': | |
| return 'en'; | |
| default: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var formatter; | |
| // Note you can define multiple lines message using an Array of Strings. | |
| Globalize.loadMessages({ | |
| en: { | |
| party: [ | |
| "{hostGender, select,", | |
| " female {{from} joined {to}} at her excursion}", | |
| " male {{from} joined {to} at his excursion}", | |
| " other {{from} joined {to} to their excursion}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Note you can define multiple lines message using an Array of Strings. | |
| Globalize.loadMessages({ | |
| en: { | |
| email: [ | |
| "You have {count, plural,", | |
| " one {one new email}", | |
| " other {{formattedCount} new emails}", | |
| ] | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Globalize.loadMessages({ | |
| en: { | |
| hello: "Hello, {0} {1}", | |
| hey: "Hey, {prefix} {last}" | |
| }, | |
| 'el': { | |
| hello: "Γιά σας, {0} {1}", | |
| hey: "Γιά σου, {prefix} {last}" | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Globalize( "el" ).formatMessage( "intro" ); // Γιά σας |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Globalize.loadMessages({ | |
| 'en': { | |
| 'intro': "Hello" | |
| }, | |
| 'el': { | |
| 'intro': "Γιά σας" | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($) { | |
| $.when( | |
| $.getJSON( 'js/vendor/cldr/en/ca-gregorian.json' ), | |
| $.getJSON( 'js/vendor/cldr/en/currencies.json' ), | |
| $.getJSON( 'js/vendor/cldr/en/numbers.json' ), | |
| $.getJSON( 'js/vendor/cldr/en/units.json' ), | |
| $.getJSON( 'js/vendor/cldr/supplemental/plurals.json' ), | |
| $.getJSON( 'js/vendor/cldr/supplemental/timeData.json' ), | |
| $.getJSON( 'js/vendor/cldr/supplemental/weekData.json' ), | |
| $.getJSON( 'js/vendor/cldr/supplemental/likelySubtags.json' ) |