1- import type { RequireAtLeastOne , UnAsConst } from '../models' ;
1+ import type { RequireAtLeastOne } from '../models' ;
22import type LangInfoTranslation from './en/language-info' ;
33import type Translation from './en/translation' ;
44
55/**
66 * Add new translatable attributes here.
77 *
8- * To add new custom data attributes for HTML intellisense, see `script /vscode-intellisense.js`.
8+ * To add new custom data attributes for HTML intellisense, see `scripts /vscode-intellisense.js`.
99 */
1010type I18nAttributes = RequireAtLeastOne < {
1111 textContent ?: string ;
@@ -21,17 +21,24 @@ type I18nAttributes = RequireAtLeastOne<{
2121 * Only use in `en` language with `as const satisfies`.
2222 */
2323export interface I18nTranslationTemplate {
24- [ key : string ] : ValidI18nTypes | string ;
24+ [ key : string ] : I18nAttributes | string | I18nTranslationTemplate ;
2525}
2626
27- type ValidI18nTypes = I18nAttributes | I18nTranslationTemplate ;
27+ /**
28+ * Maps a nested object structure to a structure where all leaf nodes are strings.
29+ *
30+ * Use to keep the same structure as the `en` i18n object for other languages.
31+ */
32+ export type I18nStructure < T > = {
33+ readonly [ K in keyof T ] : T [ K ] extends Record < string , unknown > ? I18nStructure < T [ K ] > : string ;
34+ } ;
2835
2936/**
3037 * Type for all i18n object of namespace `translation` other than `en`.
3138 */
32- export type I18nTranslation = UnAsConst < typeof Translation , ValidI18nTypes , string > ;
39+ export type I18nTranslation = I18nStructure < typeof Translation > ;
3340
3441/**
3542 * Type for all i18n object of namespace `language-info` other than `en`.
3643 */
37- export type I18nLangInfoTranslation = UnAsConst < typeof LangInfoTranslation , ValidI18nTypes , string > ;
44+ export type I18nLangInfoTranslation = I18nStructure < typeof LangInfoTranslation > ;
0 commit comments