Localizer VSCode extension
This plugin used to edit localize texts. It provide an UI to edit text then save to a json and generate code files.
Usage
- Install this plugin
- Create a file has extension
.l.json
- Setup setting localize languages and language of generate code
- Edit your texts and then use code generated
Features
- It is an editor plugin base on a json file, so can use with repository or export, copy, manual edit.
- Multiple modules by use dot in keyword, eg: common.<identity1,2,...>, module1.<identity1,2...>.
- Support generate code for Javascript, Typescript, Dart, Custom.
Custom generate: it run a command in VSCode Terminal, up to you to generate code.
- Support parameters in localize text by use curly bracket
{}
. Eg: Welcome {name}.
- Generate code to multi classes with intellisense documentation.
- Automatic translate by use Microsoft Translator. Require setup API key in VSCode Localizer settings.
Use generated codes
Example: we have a file messages.l.json
, the plugin will generate code file messages.js
, messages.ts
, messages.dart
depend on generate setting. There are a class named Message
in generated code, we will use its static method getLocalizer
to load localize texts.
The method getLocalizer
accept a parameter (optional) that is language defined in json, it will return localize texts for that language or default texts if not found.
Javascript
const msgModule = require("<path>/messages");
const language = "";
const msg = msgModule.Messages.getLocalize(language);
//get text by keyword common.ok
msg.common.ok;
//get text by keyword common.welcome, has parameter
msg.common.welcome("test");
Typescript
import { Messages } from "<path>/messages";
const language = "";
const msg = Messages.getLocalize(language);
//get text by keyword common.ok
msg.common.ok;
//get text by keyword common.welcome, has parameter
msg.common.welcome("test");
Dart
import "<path>/messages";
final language = "";
final msg = Messages.getLocalize(language);
//get text by keyword common.ok
msg.common.ok;
//get text by keyword common.welcome, has parameter
msg.common.welcome("test");