-
We want to load email templates etc. based on locale information stored on firestore. What is wrong? "node": "16" main.ts import { Locales } from './i18n/i18n-types'
import { detectLocale ,i18nObject} from './i18n/i18n-util'
const detectLocaleFromString = (str: string): Locales => {
const [language,] = str.split('-');
return detectLocale(() => [language])
}
module.exports = functions.region('asia-northeast1').runWith({
memory: '1GB',
enforceAppCheck: true // AppCheck
}).https.onCall(async (data, context): Promise<void> => {
...
//planData.members[userId].locale 'ja', 'en', 'ja-JP', 'en-US'
const detectedLocale = detectLocaleFromString(planData.members[userId].locale)
const i18n = i18nObject(detectedLocale)
console.log('userLocale', planData.members[userId].locale, 'detectedLocale', detectedLocale, 'displayLocale', i18n.locale())
// 👉 userLocale ja detectedLocale ja displayLocale
// Cannot retrieve string.
return
}) .typesafe-i18n.json {
"adapters": [
"node"
],
"baseLocale": "en",
"$schema": "https://unpkg.com/typesafe-i18n@5.24.3/schema/typesafe-i18n.json"
} i18n/en/index.ts import type { BaseTranslation } from '../i18n-types'
const en = {
locale : 'en',
} satisfies BaseTranslation
export default en i18n/ja/index.ts import type { Translation } from '../i18n-types'
const ja = {
locale : 'ja',
} satisfies Translation
export default ja |
Beta Was this translation helpful? Give feedback.
Answered by
ivanhofer
Jun 23, 2023
Replies: 1 comment 1 reply
-
Hi, you need to load your desired locale first before using it: https://github.com/ivanhofer/typesafe-i18n#calling-llkey-renders-an-empty-string |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tuclicks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, you need to load your desired locale first before using it: https://github.com/ivanhofer/typesafe-i18n#calling-llkey-renders-an-empty-string