Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yiminghe/typed-icu-message
https://github.com/yiminghe/typed-icu-message
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/yiminghe/typed-icu-message
- Owner: yiminghe
- License: mit
- Created: 2023-12-29T10:18:53.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-14T07:21:05.000Z (8 months ago)
- Last Synced: 2024-04-15T04:24:47.104Z (7 months ago)
- Language: TypeScript
- Size: 297 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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'];
```