l10n tagged template literals
npm install intl-templateA tiny i18n/l10n TTL(Tagged Template Literals) function
- intel-template
- Table of Contents
- Installation
- Usage
- Use browser specifies locale
- Use with React
- Specify slot order
- Nested
- Function slot
- Call as function
``bash`
npm install intl-template
`
import translation from "intl-template"
translation.templates["es-ES"] = {
"hello {}": "hola {}"
}
const l10n = translation.translate.bind(null, "es-ES")
const name = "willow";
console.log(l10nhello ${name})`
// => hola willow
import translation, { l10n } from "intl-template"translation.templates["es-ES"] = {
"hello {}": "hola {}"
}
// l10n = translation.translate.bind(null, navigator,language)
const name = "willow";
console.log(l10n
hello ${name})
// => hola willow
`$3
`javascriptfunction SomeComponent({ name }) {
return (
{l10nhello ${{name}}}
)
}
`$3
`
translation.templates["de-DE"] = {
"hello {} and {}": "hallo {1} und {0}"
}const l10n = translation.translate.bind(null, "de-DE")
const name1 = "willow"
const name2 = "jack"
console.log(l10n
hello ${name1} and ${name2})
// => holla jack und willow
`$3
`javascript
translation.templates["de-DE"] = {
"bill": "schmidt",
"hello {}": "hallo {1}"
}const l10n = translation.translate.bind(null, "de-DE")
l10n
hello ${l10nbill} // => hallo schmidt
`$3
`javascript
translation.templates["de-DE"] = {
"bill": "schmidt",
"hello {}": "hallo {1}"
}const l10n = translation.translate.bind(null, "de-DE")
l10n
hello ${(locale) => 123} // => hallo 123
`$3
`javascript
l10n("hello {}", name)
``