# @shopify/i18n-as

> An i18n implementation for AssemblyScript

Latest version **0.0.4** (published 2021-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @shopify/i18n-as
pnpm add @shopify/i18n-as
yarn add @shopify/i18n-as
bun add @shopify/i18n-as
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-06-10 |
| First published | 2021-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 92.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shopify Inc. |
| Maintainers | bpscott, marytal, themallen, thomaskelly, nathanpjf, shopify-dep, ismail.syed, goodforonefare, lemonmade, huguestennier, wizardlyhel, antoine.grant, tsov, andyw8-shopify, henrytao, hannachen, andrewapperley, iainmcampbell, vividviolet |

## Links

- npm: https://www.npmjs.com/package/@shopify/i18n-as
- npm.io page: https://npm.io/package/@shopify/i18n-as

## Dependencies (5)

- [pkg-dir](https://npm.io/package/pkg-dir.md) 5.0.0
- [ts-node](https://npm.io/package/ts-node.md) ^8.6.2
- [typescript](https://npm.io/package/typescript.md) ^3.8.3
- [visitor-as](https://npm.io/package/visitor-as.md) 0.3.2
- [assemblyscript-json](https://npm.io/package/assemblyscript-json.md) ^1.0.0

## Recent versions

- 0.0.4 (latest) — 2021-06-10
- 0.0.3 — 2021-05-21
- 0.0.2 — 2021-05-21
- 0.0.1 — 2021-05-21

## README

# i18n-as

[About this project](#about-this-project) | [How to use this project](#how-to-use-this-project) | [Development](#development)

## About this project
i18n-as is a localization package for [AssemblyScript](https://www.assemblyscript.org/) projects.
It works by using a compiler [transform](https://github.com/Shopify/i18n-as/blob/06bf5586fbf41a8b2cda8103016f3223eeb118dd/src/transform.ts) to make [translations](https://github.com/Shopify/i18n-as/tree/06bf5586fbf41a8b2cda8103016f3223eeb118dd/tests/integration/locales) locally accessible within the WebAssembly binary. 

## How to use this project
### Requirements
- Node is installed locally.

### Installation
```
# npm
$ npm install @shopify/i18n-as --save

# yarn
$ yarn add @shopify/i18n-as
```

### Using the Transform
Since i18n-as uses a compiler transform to read and parse translations, you need to tell the compiler to use the transform. Options:
  1. During all `asc` calls, add `--transform @shopify/i18n-as/dist/transform.js`
      - Ex. `asc entryFile.ts --transform @shopify/i18n-as/dist/transform.js`
      - If you use additional projects that compile your code like [as-pect](https://github.com/jtenner/as-pect), ensure those are configured to use this transform as well.
  2. Add a `transform` option to your `asconfig.json` file.
  ```
  // asconfig.json
  {
    ...
    "options": {
      ...
      "transform": "@shopify/i18n-as/dist/transform.js"
    }
  }
  ```

### Configuration
By default, i18n-as will look for locale files in the `/locales` folder at the project root. To configure this location, you can optionally add a `i18n.config.json` file:
```
// i18n.config.json
{
  "localeFilesDirectory": "/path/to/your/folder"
}
```


### Locale Files
Locale files should be written in JSON files and abide by the following folder structure:
```
.
├── assembly/
├── locales/
│   ├── en.json
│   └── fr.json
|   └── <locale>.json
└── i18n.config.json
```

```
// locales/<locale>.json
{
  "my translation key": "some translated value",
  "another key: "another value"
}
```

### AssemblyScript example

```
// locales/fr.json
{
  "hello": "bonjour",
}
```
```
// locales/es.json
{
  "hello": "hola",
}
```
```
// index.ts
import { translate } from '@shopify/i18n-as'

translate("fr", "hello") // => "bonjour"
translate("es", "hello") // => "hola"
translate("en", "hello") // => defaults to the key, "hello"
```

### More Documentation
Additional documentation can be found in the [wiki](https://github.com/Shopify/i18n-as/wiki).

## Development
### Quick Start
```
$ git clone https://github.com/Shopify/i18n-as.git
$ cd i18n-as
$ npm install
$ npm run test
```

### Commands
* `npm run asbuild` - build the WebAssembly binary.
* `npm run build` - compile the TypeScript transform into JavaScript.
* `npm run test` - run the tests.

---
_Source: https://npm.io/package/@shopify/i18n-as · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
