feat: localize game assets

This commit is contained in:
tresabhi committed 2025-01-14 19:22:41 -06:00
1 parent d8459d373c
commit ef9778ea96
90 files changed
+336 -251

No files matched your search

+2
View File
@@ -1 +1,3 @@
export * from './strings';
export * from './supportedLocales';
export * from './unwrapper';
+4 -4
View File
@@ -1,12 +1,12 @@
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@blitzkit/core/src/blitzkit';
import { merge } from 'lodash-es';
import type en from '../strings/en.json';
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from './supportedLocales';
export type TranslationTree = { [key: string]: TranslationNode };
export type TranslationNode = string | TranslationTree;
const files = import.meta.glob('../../lang/*.json', { eager: true });
const files = import.meta.glob('../strings/*.json', { eager: true });
export const localizedStrings: Record<string, typeof en> = {};
function nuke(object: TranslationTree) {
@@ -21,8 +21,8 @@ function nuke(object: TranslationTree) {
}
SUPPORTED_LOCALES.forEach((locale) => {
const defaultStrings = files[`../../lang/${DEFAULT_LOCALE}.json`];
const strings = files[`../../lang/${locale}.json`];
const defaultStrings = files[`../strings/${DEFAULT_LOCALE}.json`];
const strings = files[`../strings/${locale}.json`];
const mergedStrings = merge({}, defaultStrings, strings);
/**
+36
View File
@@ -0,0 +1,36 @@
export const SUPPORTED_LOCALES = [
'en',
'es',
'fr',
'ja',
'pt',
'ru',
'uk',
'zh',
] as const;
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
export const DEFAULT_LOCALE = SUPPORTED_LOCALES[0];
export const SUPPORTED_LOCALE_BLITZ_MAP: Record<SupportedLocale, string> = {
en: 'en',
es: 'es',
fr: 'fr',
ja: 'ja',
pt: 'pt',
ru: 'ru',
uk: 'uk',
zh: 'zh-Hans',
};
export const SUPPORTED_LOCALE_FLAGS: Record<SupportedLocale, string> = {
en: '🇺🇸',
es: '🇪🇸',
fr: '🇫🇷',
ja: '🇯🇵',
pt: '🇵🇹',
ru: '🇷🇺',
uk: '🇺🇦',
zh: '🇨🇳',
};
+12
View File
@@ -0,0 +1,12 @@
import { I18nString } from '@blitzkit/core';
import { DEFAULT_LOCALE } from './supportedLocales';
export function unwrapper(locale: string) {
return function (i18nString: I18nString) {
if (locale in i18nString.locales) {
return i18nString.locales[locale];
}
return i18nString.locales[DEFAULT_LOCALE];
};
}