Skip to content

Commit

Permalink
feat(core): Add support for accessible locales with `@openkit/languag…
Browse files Browse the repository at this point in the history
…e-codes`
  • Loading branch information
wootsbot committed Aug 11, 2023
1 parent ebd5ea6 commit 7ee7c13
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-squids-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'x-boilerplate': minor
---

add support for accessible locales with `@openkit/language-codes`
3 changes: 2 additions & 1 deletion env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import localeCulture from '@openkit/language-codes';
import * as z from 'zod';

const zodEnv = z.object({
Expand Down Expand Up @@ -32,7 +33,7 @@ const zodEnv = z.object({
/*
* LANGUAGE CONFIG - PUBLIC
*/
NEXT_PUBLIC_DEFAULT_LANGUAGE_KEY: z.enum(['en', 'es_mx']).optional(),
NEXT_PUBLIC_DEFAULT_LANGUAGE_KEY: z.enum([localeCulture.EN.folderName, localeCulture.ES_MX.folderName]).optional(),
});

declare global {
Expand Down
17 changes: 10 additions & 7 deletions libs/i18n/constants.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import type { En, EsMX } from '@openkit/language-codes';
import localeCulture from '@openkit/language-codes';

import locales from '@/libs/i18n/locales';

export type Language = {
key: keyof typeof locales;
dir?: 'ltr' | 'rtl';
fontScale?: number;
// https://gist.github.com/JamieMason/3748498
specCulture?: 'en-US' | 'es-MX';
specCulture?: En['culture'] | EsMX['culture'];
};

export const DEFAULT_NAMESPACE = 'common';

export const DEFAULT_LANGUAGE_KEY: Language['key'] = process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE_KEY ?? 'en';
export const DEFAULT_LANGUAGE_KEY: Language['key'] =
process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE_KEY ?? localeCulture.EN.folderName;

export const AVAILABLE_LANGUAGES: Language[] = [
{
key: 'en',
specCulture: 'en-US',
key: localeCulture.EN.folderName,
specCulture: localeCulture.EN.culture,
},
{
key: 'es_mx',
specCulture: 'es-MX',
key: localeCulture.ES_MX.folderName,
specCulture: localeCulture.ES_MX.culture,
},
];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@hookform/resolvers": "3.1.1",
"@icons-pack/react-simple-icons": "8.0.1",
"@lukemorales/query-key-factory": "1.3.2",
"@openkit/language-codes": "0.1.0-beta.6",
"@react-email/components": "0.0.7",
"@react-email/html": "0.0.4",
"@tanstack/react-query": "4.32.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 7ee7c13

@vercel
Copy link

@vercel vercel bot commented on 7ee7c13 Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.