10 examples of 'javascript get locale' in JavaScript

Every line of 'javascript get locale' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
128function getStringForCurrentLocale(locales) {
129 var locale = (
130 document.documentElement.lang ||
131 navigator.language||
132 navigator.userLanguage
133 ).substr(0, 2);
134
135 return (locales[locale]) ? locales[locale] : locales['en'];
136}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

128function getStringForCurrentLocale(locales) {
129 var locale = (
130 document.documentElement.lang ||
131 navigator.userLanguage ||
132 navigator.language
133 ).substr(0, 2);
134
135 return (locales[locale]) ? locales[locale] : locales['en'];
136}
33function getLocale(lang) {
34 if (typeof lang !== "string") {
35 lang = "en";
36 }
37 lang = lang.toLowerCase();
38 if (locale.hasOwnProperty(lang) &&
39 locale[lang] !== false) {
40 return locale[lang];
41 }
42 else {
43 if (!locale.hasOwnProperty(lang)) {
44 locale[lang] = false;
45 console.log("Warning: Localization not found for language '" +
46 lang + "'");
47 }
48 return locale.en;
49 }
50}
195export function getLocale(locale) {
196 return registry.locales[locale];
197}
19export function getLocale() {
20 return locale || 'en';
21}
36function getDefaultLocale(locale) {
37 return defaultLocales[locale] || defaultLocales['*'];
38}
61function getLocale() {
62 var DEFAULT_VALUE = 'zh'; /* 默认设置为中文 */
63 return navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || DEFAULT_VALUE;
64}
123function getLocale(locale) {
124 return (locale || '').toLowerCase()
125}
36return function get(key: string, ...args: any[]) {
37 let content = texts[key] || macroTexts[key] || defaults[key] || key
38
39 if (args.length) {
40 args.forEach((arg, index) => {
41 content = content.replace(new RegExp(`\\{${index}\\}`, 'g'), arg == null ? '' : arg)
42 })
43 }
44
45 return content
46}
81get(str) {
82 let res;
83 if (typeof strings[this.locale] === 'undefined' || typeof strings[this.locale][str] === 'undefined') {
84 res = strings['en'][str];
85 console.log('Localization of "' + str + '" in "' + this.locale + '" failed, falling back to English.');
86 } else {
87 res = strings[this.locale][str];
88 }
89 return res;
90 }

Related snippets