diff --git a/src/index.js b/src/index.js index 3dc1c21..950d9c6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,10 @@ export { default as Environment } from './Environment'; +export { default as I18n } from './i18n'; export { default as TextAnnotator } from './TextAnnotator'; export { default as WebAnnotation } from './WebAnnotation'; export * from './editor'; export * from './highlighter'; -export * from './i18n'; export * from './relations'; export * from './selection'; export * from './utils'; diff --git a/src/utils/index.js b/src/utils/index.js index 4b56e38..309c1dc 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,3 +1,5 @@ +import I18n from '../i18n'; + /** * 'Deflates' the HTML contained in the given parent node. * Deflation will completely drop empty text nodes, and replace @@ -48,6 +50,9 @@ const deflateNodeList = parents => { } +/** + * Adds MS Edge polyfills for Element.matches and .closest methods. + */ export const addPolyfills = () => { if (!Element.prototype.matches) { @@ -67,4 +72,18 @@ export const addPolyfills = () => { }; } +} + +/** + * Helper to init the i18n class with a pre-defined or auto-detected locale. + */ +export const setLocale = locale => { + try { + const l = locale === 'auto' ? + window.navigator.userLanguage || window.navigator.language : locale; + + I18n.init(l); + } catch (error) { + console.warn(`Unsupported locale '${locale}'. Falling back to default en.`); + } } \ No newline at end of file