# ma-localization-js

> Javascript implementation of the ma localization library API

Latest version **1.0.8** (published 2024-11-04) · 0 weekly downloads

## Install

```sh
npm install ma-localization-js
pnpm add ma-localization-js
yarn add ma-localization-js
bun add ma-localization-js
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2024-11-04 |
| First published | 2023-04-17 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | makeabledk, kristofferdamborg |

## Links

- npm: https://www.npmjs.com/package/ma-localization-js
- npm.io page: https://npm.io/package/ma-localization-js

## Dependencies (2)

- [js-sha256](https://npm.io/package/js-sha256.md) ^0.9.0
- [sprintf-js](https://npm.io/package/sprintf-js.md) ^1.1.2

## Recent versions

- 1.0.8 (latest) — 2024-11-04
- 1.0.7 — 2023-04-18
- 1.0.6 — 2023-04-18
- 1.0.5 — 2023-04-18
- 1.0.4 — 2023-04-18
- 1.0.3 — 2023-04-18
- 1.0.2 — 2023-04-17

## README

###### Usage

const trans = await MAlocalization('PROJECT_ID', 'API_KEY', 'https://functionEndpointUrl');

trans.setLanguage(lang);

const msg = trans.translate(key,placeholders);

const availableLocales = trans.getAvailableLanguages();

const msgsInVueFormat = trans.getVue(locale);

###### Function types

translate: (string, null | Object | Array<string | number> = null) => string;

setLanguage: (string) => boolean;

getAvailableLanguages: () => string[];

getVue: () => {[key:string]:string};

###### Vue trans example

import { createApp, nextTick } from 'vue';
import { createI18n } from 'vue-i18n';

const i18n = createI18n({ legacy: false, locale: localStorage.getItem('locale') ?? 'en', messages: defaultTranslations });
let trans: any;
let availableLocales = ['en', 'da'];

async function loadLocaleMessages() {
if (!trans) trans = await MAlocalization('PROJECT_ID', 'API_KEY', 'https://functionEndpointUrl');
availableLocales = trans.getAvailableLanguages();
availableLocales.forEach((locale) => {
const msgs = trans.getVue(locale);
i18n.global.setLocaleMessage(locale, msgs);
});
return nextTick();
}

createApp(App).use(i18n).mount('#app');
loadLocaleMessages();

---
_Source: https://npm.io/package/ma-localization-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
