Standardize locale language

This commit is contained in:
Sam Becker 2025-05-10 16:47:25 -05:00
parent cfcff69b95
commit 6ab7b2089f
4 changed files with 30 additions and 9 deletions

View File

@ -257,7 +257,7 @@ Vercel Postgres can be switched to another Postgres-compatible, pooling provider
💬   I18N
-
Partial internationalization (non-admin, user-facing text) provided for a handful of languages. If you'd like to add support for a new language, open a PR [using `US_EN`](https://github.com/sambecker/exif-photo-blog/main/src/i18n/languages/us-en.ts) for reference.
Partial internationalization (non-admin, user-facing text) provided for a handful of languages. Set your language by setting the environment variable `NEXT_PUBLIC_LOCALE`. If you'd like to add support for a new language, open a PR [using `US_EN`](https://github.com/sambecker/exif-photo-blog/main/src/i18n/locales/us-en.ts) for reference.
### Supported Languages
- `US_EN`

View File

@ -47,6 +47,8 @@ export default function AdminAppConfigurationClient({
hasAuthSecret,
hasAdminUser,
// Content
locale,
hasLocale,
hasDomain,
hasNavTitle,
hasNavCaption,
@ -289,6 +291,22 @@ export default function AdminAppConfigurationClient({
title="Content"
icon={<BiPencil size={16} />}
>
<ChecklistRow
title={`Configure language: ${locale.toLocaleUpperCase()}`}
status={hasLocale}
>
Store in environment variable
(check README for
{' '}
<AdminLink
// eslint-disable-next-line max-len
href="https://github.com/sambecker/exif-photo-blog?tab=readme-ov-file#supported-locales"
>
supported locales
</AdminLink>
):
{renderEnvVars(['NEXT_PUBLIC_LOCALE'])}
</ChecklistRow>
<ChecklistRow
title="Configure domain"
status={hasDomain}

View File

@ -5,7 +5,7 @@ import {
import { getOrderedCategoriesFromString } from '@/category';
import type { StorageType } from '@/platforms/storage';
import { makeUrlAbsolute, shortenUrl } from '@/utility/url';
import { getTextForLanguage } from '@/i18n';
import { getTextForLocale } from '@/i18n';
// HARD-CODED GLOBAL CONFIGURATION
@ -99,8 +99,8 @@ const SITE_DOMAIN_SHORT = shortenUrl(SITE_DOMAIN);
// SITE META
export const APP_TEXT = getTextForLanguage(
process.env.NEXT_PUBLIC_LANGUAGE,
export const APP_TEXT = getTextForLocale(
process.env.NEXT_PUBLIC_LOCALE,
);
export const NAV_TITLE =
@ -343,6 +343,8 @@ export const APP_CONFIGURATION = {
Boolean(process.env.ADMIN_PASSWORD)
),
// Domain
locale: process.env.NEXT_PUBLIC_LOCALE ?? 'US-EN',
hasLocale: Boolean(process.env.NEXT_PUBLIC_LOCALE),
hasDomain: Boolean(
process.env.NEXT_PUBLIC_DOMAIN ||
// Legacy environment variable

View File

@ -7,17 +7,18 @@ export type I18NDeepPartial = {
[key in keyof I18N]?: Partial<I18N[key]>;
}
export const LANGUAGES: Record<string, I18NDeepPartial | undefined> = {
export const LOCALE_TEXT: Record<string, I18NDeepPartial | undefined> = {
'pt-br': PT_BR,
};
export const getTextForLanguage = (
language = '',
export const getTextForLocale = (
locale = '',
): I18N => {
const text = US_EN;
Object.entries(LANGUAGES[language.toLocaleLowerCase()] ?? {})
Object.entries(LOCALE_TEXT[locale.toLocaleLowerCase()] ?? {})
.forEach(([key, value]) => {
// Fall back to English for missing keys
text[key as keyof I18N] = {
...text[key as keyof I18N],
...value,