-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relate input to recipients element using slot
- Loading branch information
1 parent
1165a63
commit 285e5e2
Showing
6 changed files
with
161 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export default class Internationalization { | ||
constructor(messages, defaultLocale, ...requestedLocales) { | ||
// See https://tc39.es/ecma402/#sec-bestavailablelocale | ||
const bestAvailableLocale = (availableLocales, locale) => { | ||
let candidate = locale; | ||
while(true) { | ||
if (availableLocales.includes(candidate)) return candidate; | ||
const pos = candidate.lastIndexOf('-'); | ||
if (pos === -1) return undefined; | ||
candidate = candidate.substring(0, pos); | ||
} | ||
}; | ||
|
||
// https://tc39.es/ecma402/#sec-lookupmatcher | ||
const lookupMatcher = (availableLocales, requestedLocales) => { | ||
for (const locale of requestedLocales) { | ||
const noExtensionsLocale = (new window.Intl.Locale(locale)).baseName; | ||
const availableLocale = bestAvailableLocale(availableLocales, noExtensionsLocale); | ||
if (availableLocale !== undefined) return availableLocale; | ||
} | ||
return defaultLocale; | ||
}; | ||
const locale = lookupMatcher(Object.keys(messages), requestedLocales); | ||
this._messages = messages[locale.toString()]; | ||
} | ||
|
||
getMessage(messageName) { | ||
return this._messages[messageName] && this._messages[messageName].message; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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