-
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.
- Loading branch information
1 parent
fe3d62c
commit 17a80b6
Showing
11 changed files
with
1,047 additions
and
108 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { isPlainObj } from '../shared/types'; | ||
import _ from 'lodash'; | ||
import { globalThisPolyfill } from '../shared/globalThisPolyfill'; | ||
|
||
export const lowerSnake = (str: string) => { | ||
return String(str).replace(/\s+/g, '_').toLocaleLowerCase(); | ||
}; | ||
|
||
export const mergeLocales = (target: any, source: any) => { | ||
if (isPlainObj(target) && isPlainObj(source)) { | ||
_.each(source, function (value, key) { | ||
const token = lowerSnake(key); | ||
const messages = mergeLocales(target[key] || target[token], value); | ||
target[token] = messages; | ||
}); | ||
return target; | ||
} else if (isPlainObj(source)) { | ||
const result = Array.isArray(source) ? [] : {}; | ||
_.each(source, function (value, key) { | ||
const messages = mergeLocales(undefined, value); | ||
result[lowerSnake(key)] = messages; | ||
}); | ||
return result; | ||
} | ||
return source; | ||
}; | ||
|
||
export const getBrowserLanguage = () => { | ||
/* istanbul ignore next */ | ||
if (!globalThisPolyfill.navigator) { | ||
return 'en'; | ||
} | ||
return globalThisPolyfill.navigator['browserlanguage'] || globalThisPolyfill.navigator?.language || 'en'; | ||
}; |
Oops, something went wrong.