Refactor i18n structure and update language files
- Removed old validation and common language files for English and Indonesian. - Created new language files for English and Indonesian under the updated directory structure. - Updated setup to reflect new language file paths and changed default language to English. - Modified storage keys from 'locale' to 'language' for consistency. - Added new language files for various modules including bookmarks, history, navigation, and system settings. - Introduced new booking module language files for both English and Indonesian. - Implemented a login page component with basic structure.
This commit is contained in:
@@ -294,7 +294,7 @@ class TestTransformer extends BaseDataTransformer<TestEntity2, TestDTO> {
|
||||
|
||||
transformToDTO(entity: TestEntity2): TestDTO {
|
||||
return {
|
||||
id: entity.id,
|
||||
id: entity.id as string,
|
||||
booking_code: entity.bookingCode,
|
||||
customer_name: entity.customerName,
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import commonEn from './locales/en/common.json';
|
||||
import commonId from './locales/id/common.json';
|
||||
import validationEn from './locales/en/validation.json';
|
||||
import validationId from './locales/id/validation.json';
|
||||
import commonEn from './languages/en/common.json';
|
||||
import commonId from './languages/id/common.json';
|
||||
import validationEn from './languages/en/validation.json';
|
||||
import validationId from './languages/id/validation.json';
|
||||
|
||||
const DEFAULT_LANGUAGE = 'id';
|
||||
const DEFAULT_LANGUAGE = 'en';
|
||||
const SUPPORTED_LANGUAGES = ['en', 'id'] as const;
|
||||
|
||||
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
||||
@@ -32,10 +32,10 @@ export let globalStorageAdapter: I18nStorageAdapter | undefined;
|
||||
*
|
||||
* It accepts an optional storage adapter to read the initial language.
|
||||
*/
|
||||
export async function setupI18n(config: I18nConfig = {}): Promise<void> {
|
||||
export async function setupI18n(config: I18nConfig = {}, defaultLanguage?: string): Promise<void> {
|
||||
globalStorageAdapter = config.storageAdapter;
|
||||
|
||||
let initialLng = DEFAULT_LANGUAGE;
|
||||
let initialLng = defaultLanguage ? defaultLanguage : DEFAULT_LANGUAGE;
|
||||
try {
|
||||
if (globalStorageAdapter) {
|
||||
const storedLng = await globalStorageAdapter.getLanguage();
|
||||
|
||||
@@ -48,7 +48,7 @@ Object.defineProperty(globalThis, 'localStorage', {
|
||||
|
||||
const TestStorageKey = {
|
||||
THEME: 'theme',
|
||||
LOCALE: 'locale',
|
||||
LANGUAGE: 'language',
|
||||
ACCESS_TOKEN: 'access_token',
|
||||
REFRESH_TOKEN: 'refresh_token',
|
||||
USER_PROFILE: 'user_profile',
|
||||
@@ -62,7 +62,7 @@ const ENCRYPTED_KEYS = new Set<TestStorageKeyValue>([
|
||||
TestStorageKey.USER_PROFILE,
|
||||
]);
|
||||
|
||||
const PLAIN_KEYS = new Set<TestStorageKeyValue>([TestStorageKey.THEME, TestStorageKey.LOCALE]);
|
||||
const PLAIN_KEYS = new Set<TestStorageKeyValue>([TestStorageKey.THEME, TestStorageKey.LANGUAGE]);
|
||||
|
||||
interface TestUser {
|
||||
id: number;
|
||||
@@ -108,10 +108,10 @@ describe('LocalStorageService', () => {
|
||||
});
|
||||
|
||||
it('stores plain JSON without encryption for non-sensitive keys', async () => {
|
||||
await storage.setItem(TestStorageKey.LOCALE, 'en-US');
|
||||
await storage.setItem(TestStorageKey.LANGUAGE, 'en-US');
|
||||
|
||||
expect(mockEncrypt).not.toHaveBeenCalled();
|
||||
expect(mockLocalStorage.setItem).toHaveBeenCalledWith(TestStorageKey.LOCALE, '"en-US"');
|
||||
expect(mockLocalStorage.setItem).toHaveBeenCalledWith(TestStorageKey.LANGUAGE, '"en-US"');
|
||||
});
|
||||
|
||||
it('encrypts sensitive keys (ACCESS_TOKEN)', async () => {
|
||||
@@ -194,7 +194,7 @@ describe('LocalStorageService', () => {
|
||||
describe('clear', () => {
|
||||
it('clears all keys from storage', async () => {
|
||||
await storage.setItem(TestStorageKey.THEME, 'dark');
|
||||
await storage.setItem(TestStorageKey.LOCALE, 'en');
|
||||
await storage.setItem(TestStorageKey.LANGUAGE, 'en');
|
||||
await storage.clear();
|
||||
|
||||
expect(mockLocalStorage.clear).toHaveBeenCalled();
|
||||
@@ -220,11 +220,11 @@ describe('LocalStorageService', () => {
|
||||
describe('keys', () => {
|
||||
it('returns all stored keys', async () => {
|
||||
await storage.setItem(TestStorageKey.THEME, 'dark');
|
||||
await storage.setItem(TestStorageKey.LOCALE, 'en');
|
||||
await storage.setItem(TestStorageKey.LANGUAGE, 'en');
|
||||
|
||||
const allKeys = await storage.keys();
|
||||
expect(allKeys).toContain(TestStorageKey.THEME);
|
||||
expect(allKeys).toContain(TestStorageKey.LOCALE);
|
||||
expect(allKeys).toContain(TestStorageKey.LANGUAGE);
|
||||
expect(allKeys).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -248,8 +248,8 @@ describe('LocalStorageService', () => {
|
||||
expect(ENCRYPTED_KEYS.has(TestStorageKey.THEME)).toBe(false);
|
||||
});
|
||||
|
||||
it('LOCALE is NOT in ENCRYPTED_KEYS', () => {
|
||||
expect(ENCRYPTED_KEYS.has(TestStorageKey.LOCALE)).toBe(false);
|
||||
it('LANGUAGE is NOT in ENCRYPTED_KEYS', () => {
|
||||
expect(ENCRYPTED_KEYS.has(TestStorageKey.LANGUAGE)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user