@7y1o/localize 中文文档教程
Localize
用于国际化项目的轻量级且非常快速的库
Setup
npm i @7y1o/localize
Usage
此示例描述了如何在 Svelte 中使用该库:
<script>
import Localize from '@7y1o/localize';
// Libs
import LibActions from '...';
import LibPage from '...';
// Initialize library
const loc = new Localize(
['ru', 'en', 'ua'], // Languages list
'ru', // Default language
LibActions, LibPage // Localization libraries
);
// Form controller
const controller = {
login: '',
password: ''
};
// Submit action
const submitForm = () => {
// some actions
};
</script>
<main>
<div class="form">
<h1>{loc.get('form_heading')}</h1>
<p>{loc.get('form_subtext')}</p>
<input type="text" placeholder={loc.get('form_login')} bind:value={controller.login}/>
<input type="password" placeholder={loc.get('form_password')} bind:value={controller.password}/>
<button on:click={submitForm}>{loc.get('action_submit')}</button>
</div>
</main>
Available methods
- constructor (langs, defLang, …libs):
- parameters:
- langs { array(string) } - list of available languages
- defLang { string } - default language if not defined in localstorage
- libs { array(any) } - structure of translation library
- parameters:
- get (key): returns translated string or key if not found
- parameters:
- key { string } - desired translation key
- parameters:
- switch (lang): switch to language described in languages list
- parameters:
- lang { string } - language in languages list
- parameters:
Localize
Lightweight and very fast library for internationalizing projects
Setup
npm i @7y1o/localize
Usage
This example describes how to use the library in Svelte:
<script>
import Localize from '@7y1o/localize';
// Libs
import LibActions from '...';
import LibPage from '...';
// Initialize library
const loc = new Localize(
['ru', 'en', 'ua'], // Languages list
'ru', // Default language
LibActions, LibPage // Localization libraries
);
// Form controller
const controller = {
login: '',
password: ''
};
// Submit action
const submitForm = () => {
// some actions
};
</script>
<main>
<div class="form">
<h1>{loc.get('form_heading')}</h1>
<p>{loc.get('form_subtext')}</p>
<input type="text" placeholder={loc.get('form_login')} bind:value={controller.login}/>
<input type="password" placeholder={loc.get('form_password')} bind:value={controller.password}/>
<button on:click={submitForm}>{loc.get('action_submit')}</button>
</div>
</main>
Available methods
- constructor (langs, defLang, …libs):
- parameters:
- langs { array(string) } - list of available languages
- defLang { string } - default language if not defined in localstorage
- libs { array(any) } - structure of translation library
- parameters:
- get (key): returns translated string or key if not found
- parameters:
- key { string } - desired translation key
- parameters:
- switch (lang): switch to language described in languages list
- parameters:
- lang { string } - language in languages list
- parameters:
更多
你可能也喜欢
- 291dev-react-components 中文文档教程
- 500wallpaper 中文文档教程
- @0bsnetwork/zbs-transactions 中文文档教程
- @10stars/eslint-plugin-react-hooks 中文文档教程
- @10up/component-navigation 中文文档教程
- @2plgiap/react-leaflet-control 中文文档教程
- @_000407/singlish.js 中文文档教程
- @a-ui/flexboxgrid 中文文档教程
- @aaronmaturen/monofun-anchor 中文文档教程
- @abcum/ember-visuals 中文文档教程