Add romanize function
This commit is contained in:
@@ -2,6 +2,15 @@ const i18n = require('i18n')
|
||||
const YAML = require('yaml')
|
||||
const path = require("path")
|
||||
|
||||
const { transliterate } = require("transliteration")
|
||||
|
||||
const nonLatinPattern = /[^\u0000-\u007F]+/;
|
||||
|
||||
const needsRomanization = (text) => {
|
||||
// Regex pattern to match non-Latin characters
|
||||
return nonLatinPattern.test(text);
|
||||
}
|
||||
|
||||
module.exports.baseLocale = "en"
|
||||
module.exports.missingKeys = []
|
||||
i18n.configure({
|
||||
@@ -33,13 +42,20 @@ BaseLocaleKeys.forEach(baseLocaleKey => {
|
||||
i18n.__h(baseLocaleKey)
|
||||
})
|
||||
|
||||
module.exports.romanize = (text) => {
|
||||
return needsRomanization(text) ? transliterate(text) : text;
|
||||
}
|
||||
|
||||
module.exports.getText = (locale, key, substitution = null) => {
|
||||
if (BaseLocaleKeys.includes(key)) {
|
||||
// Check if substitions need to be made...
|
||||
return i18n.__({
|
||||
phrase: key,
|
||||
locale: locale
|
||||
}, substitution)
|
||||
return i18n.__(
|
||||
{
|
||||
phrase: key,
|
||||
locale: locale
|
||||
},
|
||||
substitution
|
||||
);
|
||||
} else {
|
||||
// User requested a phrase we don't know
|
||||
return `+404-${key}-${locale}`
|
||||
|
||||
Reference in New Issue
Block a user