Skip to content

Translation

Xueping edited this page Jun 5, 2020 · 5 revisions

Organize Language resources

Put language items into resource files which are created in different directories named by the language id. See the example.

hello-world=Hello, world
title = %s Demo
email = Email address
password = Password
submit = Submit

Basic usage

I18n i18n = new I18n();
i18n.loadLangResources("./resources/translations");
i18n.defaultLocale = "en-us";
writeln(i18n.trans("hello-world"));                     // Print: Hello, world
writeln(i18n.trans("title", "Hunt Framework"));         // Print: Hunt Framework Demo
writeln(i18n.transWithLocale("zh-cn", "hello-world"));  // Print: 你好,世界

Use in Controller

setLocale("zh-cn");
writeln(trans("email.title"));                          // Print: 标题

Use in View

<title>{{trans("title",app.name)}}</title>

See the demo.

Clone this wiki locally