-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(i18n): add types for translation keys
- Loading branch information
1 parent
4d3c04b
commit d44159e
Showing
9 changed files
with
64 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import type { I18nTranslation } from "../template"; | ||
import type { I18nTranslation } from '../models'; | ||
|
||
const languageInfo: I18nTranslation = { | ||
artTemplateDesc: { | ||
textContent: "" | ||
} | ||
artTemplateDesc: { | ||
textContent: '', | ||
}, | ||
}; | ||
|
||
export default languageInfo; |
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import type { I18nTranslation } from "../template"; | ||
import type { I18nTranslation } from '../models'; | ||
|
||
const translation: I18nTranslation = { | ||
welcome: { | ||
textContent: "مرحبا" | ||
} | ||
welcome: 'مرحبا', | ||
}; | ||
|
||
export default translation; |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import type { I18nTranslation } from "../template"; | ||
import { type I18nTranslationTemplate } from '../models'; | ||
|
||
const languageInfo: I18nTranslation = { | ||
artTemplateDesc: { | ||
textContent: "High performance JavaScript templating engine." | ||
} | ||
}; | ||
// This is used as a template for other translations. | ||
// Other translations should be typed like this: | ||
// const languageInfo: I18nTranslation = { /* translation here */ }; | ||
const languageInfo = { | ||
artTemplateDesc: { | ||
textContent: 'High performance JavaScript templating engine.', | ||
}, | ||
} as const satisfies I18nTranslationTemplate; | ||
|
||
export default languageInfo; |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import type { I18nTranslation } from "../template"; | ||
import { type I18nTranslationTemplate } from '../models'; | ||
|
||
const translation: I18nTranslation = { | ||
welcome: { | ||
textContent: "Welcome" | ||
} | ||
}; | ||
// This is used as a template for other translations. | ||
// Other translations should be typed like this: | ||
// const translation: I18nTranslation = { /* translation here */ }; | ||
const translation = { | ||
welcome: 'Welcome', | ||
} as const satisfies I18nTranslationTemplate; | ||
|
||
export default translation; |
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,31 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import type translation from './en/translation'; | ||
import type LangInfoTranslation from './en/language-info'; | ||
|
||
// Report error when no property is provided | ||
type RequireAtLeastOne<T> = { | ||
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>; | ||
}[keyof T]; | ||
|
||
type I18nAttributes = RequireAtLeastOne<{ | ||
textContent?: string; | ||
innerHTML?: string; | ||
title?: string; | ||
'data-hint'?: string; | ||
}>; | ||
|
||
export interface I18nTranslationTemplate { | ||
[key: string]: I18nAttributes | string; | ||
} | ||
|
||
export type I18nTranslation = RequireAtLeastOne< | ||
{ | ||
[key in keyof typeof translation]: (typeof translation)[key] extends I18nAttributes | ||
? I18nAttributes | ||
: string; | ||
} & { | ||
[key in keyof typeof LangInfoTranslation]: (typeof LangInfoTranslation)[key] extends I18nAttributes | ||
? I18nAttributes | ||
: string; | ||
} | ||
>; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import type { I18nTranslation } from "../template"; | ||
import type { I18nTranslation } from '../models'; | ||
|
||
const languageInfo: I18nTranslation = { | ||
artTemplateDesc: { | ||
textContent: "高性能 JavaScript 模板引擎。" | ||
} | ||
artTemplateDesc: { | ||
textContent: '高性能 JavaScript 模板引擎。', | ||
}, | ||
}; | ||
|
||
export default languageInfo; |
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import type { I18nTranslation } from "../template"; | ||
import type { I18nTranslation } from '../models'; | ||
|
||
const translation: I18nTranslation = { | ||
welcome: { | ||
textContent: "欢迎" | ||
} | ||
welcome: '欢迎', | ||
}; | ||
|
||
export default translation; |
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