{"id":23377978,"url":"https://github.com/beyondjs/languages","last_synced_at":"2025-04-08T04:49:58.920Z","repository":{"id":253717126,"uuid":"844293163","full_name":"beyondjs/languages","owner":"beyondjs","description":"A reactive language management system for multilingual applications. Automatically detects and configures supported languages, provides persistent language preferences, and triggers events on language changes.","archived":false,"fork":false,"pushed_at":"2024-08-19T00:16:34.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-14T03:34:38.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beyondjs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-19T00:16:32.000Z","updated_at":"2024-08-19T00:32:35.000Z","dependencies_parsed_at":"2024-08-19T02:44:01.947Z","dependency_job_id":"f5861069-be69-4ea2-95f3-0c8c4d942c09","html_url":"https://github.com/beyondjs/languages","commit_stats":null,"previous_names":["beyondjs/languages"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Flanguages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Flanguages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Flanguages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondjs%2Flanguages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beyondjs","download_url":"https://codeload.github.com/beyondjs/languages/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247779763,"owners_count":20994572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-21T18:33:41.470Z","updated_at":"2025-04-08T04:49:58.900Z","avatar_url":"https://github.com/beyondjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `beyond-js/languages`\n\nThis package provides a reactive system for managing the current language in a multilingual application. It handles\nlanguage detection, setting, and change events, making it easy to integrate language configuration into your project.\n\n## Features\n\n-   Reactive language management.\n-   Supports custom default and supported languages.\n-   Automatically detects and sets language based on the device’s settings or previously configured values.\n-   Persistence using `localStorage` for language preference.\n-   Built-in event system to react to language changes.\n\n## Installation\n\nInstall the package using npm or yarn:\n\n```bash\nnpm install beyond-js/languages\n```\n\nor\n\n```bash\nyarn add beyond-js/languages\n```\n\n## Usage\n\n### Initializing the Language Manager\n\nThe language management system is initialized automatically when you create an instance of the `Languages` class. The\nclass fetches the language configuration from your project’s configuration file.\n\n```typescript\nimport { languages } from 'beyond-js/languages';\n\n// Wait until the language configuration is ready\nawait languages.ready;\n\n// Access the current language\nconsole.log(languages.current);\n```\n\n### Configuration\n\nThe `Languages` class reads language specifications from a configuration file in your project. The configuration should\ndefine the default language and the supported languages:\n\n```json\n{\n\t\"languages\": {\n\t\t\"default\": \"en\",\n\t\t\"supported\": [\"en\", \"es\", \"fr\", \"de\"]\n\t}\n}\n```\n\n### Language Properties\n\n-   **`languages.current`**: Returns the currently selected language.\n-   **`languages.default`**: Returns the default language specified in the configuration.\n-   **`languages.supported`**: Returns a set of supported languages.\n-   **`languages.ready`**: A promise that resolves when the configuration is loaded.\n-   **`languages.fetched`**: Indicates if the configuration has been fetched.\n\n### Setting the Current Language\n\nYou can change the current language using the following code:\n\n```typescript\nlanguages.current = 'es'; // Change the language to Spanish\n```\n\n### Handling Language Change Events\n\nThe package uses an event system that allows you to listen to changes in the language setting:\n\n```typescript\nlanguages.on('change', () =\u003e {\n\tconsole.log('Language has been changed to:', languages.current);\n});\n```\n\n## API Reference\n\n### `Languages` Class\n\n#### Properties\n\n-   **`current: string`**  \n    Gets or sets the current language.\n\n-   **`default: string`**  \n    The default language specified in the configuration.\n\n-   **`supported: Set\u003cstring\u003e`**  \n    The set of supported languages.\n\n-   **`ready: Promise\u003cvoid\u003e`**  \n    A promise that resolves when the language configuration is ready.\n\n-   **`fetched: boolean`**  \n    Indicates whether the configuration has been fetched.\n\n#### Methods\n\n-   **`on(event: string, callback: () =\u003e void): void`**  \n    Registers an event listener for language change events.\n\n## Example\n\n```typescript\nimport { languages } from 'beyond-js/languages';\n\nasync function initialize() {\n\tawait languages.ready;\n\n\tconsole.log('Current language:', languages.current);\n\n\tlanguages.on('change', () =\u003e {\n\t\tconsole.log('Language changed to:', languages.current);\n\t});\n\n\tlanguages.current = 'fr'; // Change language to French\n}\n\ninitialize();\n```\n\n## License\n\nThis package is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondjs%2Flanguages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeyondjs%2Flanguages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondjs%2Flanguages/lists"}