• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

albertodev01/TLanguages: Localization tool for VCL and FMX

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

albertodev01/TLanguages

开源软件地址(OpenSource Url):

https://github.com/albertodev01/TLanguages

开源编程语言(OpenSource Language):

Pascal 100.0%

开源软件介绍(OpenSource Introduction):

TLanguages

This is a component written in Delphi that works with VCL and FMX and can be used to localize (translate) your Windows/iOS/Android applications. You'll have to install a component in the IDE in order to load the localized strings stored in a .json file; this file will be created using the apposite Editor.

There is a Default language which contains the IDs of the strings. You can add using the apposite buttons new words or language and once you're done store your work in a json file. In the sections below I'll show you how to install everything properly and then run an example.

Install

To install the component just follow these steps:

  1. Download this repo and open ProjectLanguages.dproj in the Component folder
  2. In the Project Manager (on the top right) double click ProjectLanguages.bpl to select it
  3. Now ProjectLanguages.bpl should be selected. Right click and do Compile, then Build and finally Install

Do not forget to add the source files to the library path of the IDE. To do this go on Tools > Options > Delphi Options > Library and for each platform add the path to the folder containing the sources of the component.

Now you just need to open the Editor folder, open ProjectLanguages.dproj and then give a Compile > Build to create the executable of the Editor for your machine. The editor has been written with FMX so it can be compiled on Win32, Win64 and OS X!

Usage

  1. Open the editor and create a New Language File using the apposite button above (or use Browse to open a file if you had already created one). Now you can use the buttons to add words/languages and the table to edit the values that you want to assign to the localized strings. I have created this as example:

  1. Once you have finished, click Save Edits and open Delphi. Create a new project (VCL or FMX), drop the Language1 component in the form. Just as test, add a TLabel component in the form.

  2. Now go on Project > Resources and Images > Add... > select the .json file generated with the Editor > give it an Identifier > select RCDATA as type > click Ok.

Now you have finished the setup and you can start using the component. This code shows how to initialize the component in the FormCreate and then how to localize strings.

procedure TForm1.FormCreate(Sender: TObject);
begin
  //The 'jsonResourceId' is the Identifier I was talking about on point number 3
  Language1.setSource('jsonResourceId');
  Language1.setLanguage('Default');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  Language1.setLanguage('it');
  //The caption is now 'casa'
  Label1.Caption := Language1.localize('home');

  Language1.setLanguage('fr');
  //The caption is now 'maison'
  Label1.Caption := Language1.localize('home');

end;

The .json file with the localizations will be attached to you executable and it will increase the final size but consider that a json file is basically a text file with some chars inside so it's not huge. In a project of mine there are 4 languages with 50 words each and the file size it's less than 5 kb.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap