@localazy/api-client
Version:
Official Node.js client for the Localazy API, providing a simple and type-safe way to integrate localization features into your JavaScript and TypeScript projects.
95 lines (61 loc) β’ 4.6 kB
Markdown
<div align="center">
[<img src="https://localazy.com/directus9/assets/9fc36b9c-81b7-4dbf-bd82-b64cd984090f" width="285" height="50" alt="Localazy" >](https://localazy.com)
Node.js client for the [Localazy API](https://localazy.com/docs/api), providing a simple and type-safe way to integrate localization features into your JavaScript and TypeScript projects.
[](https://www.npmjs.com/package/@localazy/api-client)
[](https://github.com/localazy)
[](https://github.com/localazy/api-client/blob/main/LICENSE)<br>
[](https://github.com/localazy/api-client/actions)
[](https://bundlephobia.com/package/@localazy/api-client)
</div>
```bash
npm install @localazy/api-client
```
```javascript
import { ApiClient } from '@localazy/api-client';
const json = { en: { tooltip: 'Elegant unicorn' } }; // Get text to translate.
const api = new ApiClient({ authToken: 'your-project-token' }); // Create Api client.
const project = await api.projects.first(); // Get Localazy project.
const file = await api.import.json({ project, json }); // Import source keys.
const fr = await api.export.json({ project, file, langs: ['fr'] }); // Export translated keys.
console.log(fr); // π¦ { fr: { tooltip: 'Licorne Γ©lΓ©gante' } }
```
```javascript
import { ApiClient, Project, I18nJson, Locales } from '@localazy/api-client';
const json: I18nJson = { en: { tooltip: 'Elegant unicorn' } };
const api: ApiClient = new ApiClient({ authToken: 'your-project-token' });
const project: Project = await api.projects.first();
const file: File = await api.import.json({ project, json: json });
const fr: I18nJson = await api.export.json({ project, file, langs: [Locales.FRENCH] });
```
You can obtain the project token at https://localazy.com/developer/tokens.
The project token is permitted to read and write to the single project.
- [API Client reference](docs/api-client-reference.md)
- [Examples](examples)
- [Migration guide from `ts-api@1.x.x` to `api-client@2.0.0`](docs/migration-guide-from-v1-to-v2.md)
- [Changelog](CHANGELOG.md)
- [Localazy API documentation](https://localazy.com/docs/api)
- [Articles about the Localazy API](https://localazy.com/tags/api)
Join the [Localazy Discussion Forum](https://discuss.localazy.com/) to discuss all things localization.
If you encounter any problems or have questions, you can use our forum, GitHub issues or contact us at
team@localazy.com.
Check out other npm packages from Localazy:
| | NPM package | Description |
| :------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------- |
| <img src="https://localazy.com/directus9/assets/3f76ff7b-0e74-4046-bb03-4ca99c3b66d5" width="50" height="50" alt="cli"> | [@localazy/cli](https://www.npmjs.com/package/@localazy/cli) | Localazy CLI tool. |
| <img src="https://localazy.com/directus9/assets/20866781-e69b-4e01-9456-05437487b75c" width="50" height="50" alt="localazy-api"> | [@localazy/api-client](https://www.npmjs.com/package/@localazy/api-client) | Localazy API client. |
| <img src="https://localazy.com/directus9/assets/c9e70e4f-8136-432a-8d82-53c3501a9eb4" width="50" height="50" alt="languages"> | [@localazy/languages](https://www.npmjs.com/package/@localazy/languages) | List of all languages supported by Localazy. |
| <img src="https://localazy.com/directus9/assets/1dd05c76-e517-4aea-a3d8-49cfddb40056" width="50" height="50" alt="strapi"> | [@localazy/strapi-plugin](https://www.npmjs.com/package/@localazy/strapi-plugin) | The official Localazy Strapi plugin. |
Discover all available [integration options and localization examples](https://github.com/localazy).
Code released under the [MIT license](LICENSE).