Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yiminghe/typed-icu-message


https://github.com/yiminghe/typed-icu-message

Last synced: 9 days ago
JSON representation

Awesome Lists containing this project

README

        

# typed-icu-message

transform icu language message json to typescript type definition

[![NPM version](https://badge.fury.io/js/typed-icu-message.png)](http://badge.fury.io/js/typed-icu-message)
[![NPM downloads](http://img.shields.io/npm/dm/typed-icu-message.svg)](https://npmjs.org/package/typed-icu-message)

## demo
![1](./demo/1.png)
![2](./demo/2.png)
![3](./demo/3.png)
![4](./demo/4.png)

## usage

```shell
npm install typed-icu-message
```

```typescript
import { getTsTypesFromRes } from 'typed-icu-message';

const code = getTsTypesFromRes({
zh: {
'a': '一 {b} {c}',
'c': '二 {num, plural, =0 {{num2}} =1 {{num2}} other {{num2}}}'
},
en: {
'a': 'one {b} {c}',
'c': 'two {num, plural, =0 {{num2}} =1 {{num2}} other {{num2}}}'
}
});
```

generated code:
```typescript

/* eslint-disable */
export interface I18nRes {

"a": {
returnType: "一 {b} {c}" | "one {b} {c}";

variableType: {
"b": any;
"c": any;
};
}
"c": {
returnType: "二 {num, plural, =0 {{num2}} =1 {{num2}} other {{num2}}}" | "two {num, plural, =0 {{num2}} =1 {{num2}} other {{num2}}}";

variableType: {
"num": number;
"num2": any;
};
}
}

export type I18nResKeys = keyof I18nRes;

export type I18nNsType = string;

export type I18nTranslate = (
...args:
| [p: T,
options: I18nRes[T]['variableType'] & {
ns?: I18nNsType|I18nNsType[];
defaultValue?: string;
} ]
| [p: T,
defaultValue: string,
options: I18nRes[T]['variableType'] & {ns?: I18nNsType|I18nNsType[];} ]
) => I18nRes[T]['returnType'];
```