Core Foundation SDK - Localization, Utilities, and Essentials
npm install core-foundation-sdkcore-foundation-sdk provides that base with a focus on Developer Experience (DX) and Performance.
L. and get autocomplete for your keys.
bash
npm install core-foundation-sdk
`
---
ā” Quick Start
$3
Call SDK.init() at the root of your application (e.g., index.ts or App.tsx).
`typescript
import { SDK } from 'core-foundation-sdk';
await SDK.init({
// š Set your default language
defaultLanguage: 'en',
// š ļø DEV MODE ONLY: Auto-generate missing keys!
// This will create 'locales/en.json' if it doesn't exist.
saveMissing: process.env.NODE_ENV === 'development',
});
`
$3
Stop using string keys like t('welcome_msg'). Use the L object.
`typescript
import { L } from 'core-foundation-sdk';
// ā
Simple Usage (String Coercion)
console.log(L.btn_save); // Output: "Save"
// ā
Interpolation (Function Call)
// Key: "welcome": "Welcome, {{name}}!"
console.log(L.welcome({ name: 'Ali' })); // Output: "Welcome, Ali!"
// ā
React / JSX Support
export const MyComponent = () => (
);
`
$3
Change languages instantly. The SDK handles loading and caching.
`typescript
import { SDK } from 'core-foundation-sdk';
await SDK.changeLanguage('ur');
console.log(L.btn_save); // Output: "Ł
ŲŁŁŲø Ś©Ų±ŪŚŗ"
`
---
āļø Advanced Configuration
You can customize the SDK to fit your project structure.
`typescript
interface SDKConfig {
/* Default language on startup /
defaultLanguage: SupportedLanguage;
/* Enable auto-generation of missing keys (Dev mode recommended) /
saveMissing?: boolean;
/**
* Where to save missing keys?
* Default: 'locales' (project root)
*/
localesPath?: string;
/* Enable debug logs /
debug?: boolean;
}
`
$3
1. Set saveMissing: true.
2. Use a new key in your code: console.log(L.new_amazing_feature).
3. Check your terminal: [SDK] Batch Saved: Added 1 key to en.json.
4. Check locales/en.json: The key is there! šŖ
---
š Project Structure
Verified "Option A" flatten structure for simplicity:
`text
my-app/
āāā locales/
ā āāā en.json # Master English Strings
ā āāā ur.json # Urdu Strings
ā āāā es.json # Spanish (Auto-created if you switch to 'es')
āāā src/
ā āāā index.ts
āāā package.json
`
---
š¤ Contributing
We welcome contributions! Please see CONTRIBUTING.md` for details.