https://github.com/locize/vue-i18n-translation-parser
parses vue-i18n translations to AST
https://github.com/locize/vue-i18n-translation-parser
Last synced: 12 months ago
JSON representation
parses vue-i18n translations to AST
- Host: GitHub
- URL: https://github.com/locize/vue-i18n-translation-parser
- Owner: locize
- License: mit
- Created: 2018-06-29T18:24:48.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-31T06:15:07.000Z (over 1 year ago)
- Last Synced: 2025-06-13T23:02:15.823Z (12 months ago)
- Language: JavaScript
- Size: 532 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Introduction
This is a module to parse an vue-i18n translation string into an AST and back to a string.
# Getting started
Source can be loaded via [npm](https://www.npmjs.com/package/vue-i18n-translation-parser) or downloaded from this repo.
```
# npm package
$ npm install vue-i18n-translation-parser
```
# Sample
```js
import { parse, stringify } from 'vue-i18n-translation-parser';
const AST = parse('
test');
// will return
/*
[
{
"type": "tag",
"name": "div",
"voidElement": false,
"attrs": {},
"children": [
{
"type": "text",
"content": "test"
}
]
}
]
*/
stringify(AST); // -> 'test'
parse('test {{val}} text {{- encoded}} with {{val, format}} some $t{nesting} help');
// will return
/*
[
{
"type": "text",
"content": "test "
},
{
"type": "interpolation",
"raw": "{{val}}",
"prefix": "{{",
"suffix": "}}",
"content": "val",
"variable": "val"
},
{
"type": "text",
"content": " text "
},
{
"type": "interpolation_unescaped",
"raw": "{{- encoded}}",
"prefix": "{{-",
"suffix": "}}",
"content": " encoded",
"variable": "encoded"
},
{
"type": "text",
"content": " with "
},
{
"type": "interpolation",
"raw": "{{val, format}}",
"prefix": "{{",
"suffix": "}}",
"content": "val, format",
"variable": "val, format"
},
{
"type": "text",
"content": " some "
},
{
"type": "nesting",
"raw": "$t{nesting}",
"prefix": "$t{",
"suffix": "}",
"content": "nesting",
"variable": "nesting"
},
{
"type": "text",
"content": " help"
}
]
*/
```