forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternationalization.js
More file actions
55 lines (52 loc) · 1.57 KB
/
internationalization.js
File metadata and controls
55 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
let resources;
// Do not include translations in the minified js
if (typeof IS_MINIFIED === 'undefined') {
resources = require('../../translations').default;
}
/**
* This is our translation function. Give it a key and
* it will retreive the appropriate string
* (within supported languages) according to the
* user's browser's language settings.
* @function translator
* @param {String} key a key that corresponds to a message in our translation files
* @param {Object} values values for use in the message under the given `key`
* @returns {String} message (with values inserted) in the user's browser language
* @private
*/
export let translator = () => {
console.debug('p5.js translator called before translations were loaded');
return '';
};
// (We'll set this to a real value in the init function below!)
/**
* Set up our translation function, with loaded languages
*/
export const initialize = () =>
new Promise((resolve, reject) => {
i18next
.use(LanguageDetector)
.init({
fallbackLng: 'en',
nestingPrefix: '$tr(',
nestingSuffix: ')',
defaultNS: 'translation',
returnEmptyString: false,
interpolation: {
escapeValue: false
},
detection: {
checkWhitelist: false
},
resources
})
.then(
translateFn => {
translator = translateFn;
resolve();
},
e => reject(`Translations failed to load (${e})`)
);
});