多语包需求说明.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. CNPack - MultiLang 多国语言翻译元件包需求规范说明书 By Riceball<riceball@cq118.com>
  2. 开发平台:D34567, C456, K123 以上版本
  3. 主要目的:通过开发该元件包,我们期望用最简单的方式轻松的将应用程序从一种语言翻译为另一种语言(在程序内部)并且可以实时切换,不需要大量的编程处理(只需要将翻译元件放到窗体或数据模块上),你所作的只是集中精力在翻译上即可。
  4. 介绍:
  5. 一、核心元件介绍
  6. MultiLang 多国语言翻译元件包主要有三种核心元件组成: 多国语言贮藏库元件, 多国语言管理器元件, 多国语言翻译者元件。
  7. 1、多国语言贮藏库元件(Language DataStorage Components)
  8. 我们在多国语言贮藏库元件中保存翻译的语言字符串,通过选择不同的多国语言贮藏库元件派生类,你可以将多国语言保存到 Ini
  9. 文件,XML 文件,数据库或者内部 Exe 文件中。
  10. 注[riceball]:
  11. I.在第一阶段的开发中我们将只实现 TIniLanguageFileStorage
  12. 多国语言贮藏库元件,将多国语言保存到Ini文件中。另外,当然你也可以开发自己的多国语言贮藏库元件,欢迎加入开发的队伍。
  13. II.创建新语言(文件),翻译的文本,保存,选择语言,也就是语言文件的管理的实际实现也要在此。
  14. 有效的多国语言(已翻译的)可以通过属性 TCustomLanguageStorage.Languages 和
  15. TCustomLanguageStorage.LanguageCount 访问。当前使用的语言可以通过
  16. TCustomLanguageStorage.CurrentLanguage 属性访问或设置。
  17. 元件列表:
  18. * TCustomLanguageStorage (抽象元件类只供开发用户派生用。)
  19. * TCustomLanguageFileStorage(抽象元件类只供开发用户派生用。)
  20. * TIniLanguageFileStorage (供开发用户派生用。)
  21. * TCnIniLanguageFileStorage (放在元件面板上供一般用户使用。)
  22. 2、多国语言管理器元件(Language Manager Components)
  23. 多国语言管理器元件是多国语言翻译开发包的核心元件。该元件有能力管理多种语言,语言的实时切换以及自动套用默认语言显示应用程序。
  24. 注意: 一个应用程序有且只能拥有一个多国语言管理器元件! 换句话说,一个应用有且只能有一个 TCustomLanguageManager 实例, 你可以通过GLanguageManager函数访问这个唯一实例.
  25. 元件列表:
  26. * TCustomLanguageManager (供开发用户派生用。)
  27. * TCnLanguageManager (放在元件面板上供一般用户使用。)
  28. * TCustomLanguageFormManager(供开发用户派生用。)
  29. * TCnLanguageFormManager (放在元件面板上供一般用户使用。)
  30. 3、多国语言翻译者元件(Translator Component)
  31. 多国语言翻译者元件是多国语言翻译开发包的辅助元件(辅助懒人的),一般放在窗体上(每个窗体只允许有一个翻译者元件),这等于告诉翻译管理器该窗体需要翻译。与此同时用于在
  32. Delphi IDE 集成环境下的辅助翻译(如创建该窗体的指定语言的翻译文件,编辑窗体的翻译文件等等)。
  33. 元件列表:
  34. * TCustomTranslator (供开发用户派生用。)
  35. * TCnTranslator (放在元件面板上供一般用户使用。)
  36. 二、使用指南
  37. 使用步骤如下:
  38. 1).在主窗体或数据模块(供其它模块、窗体调用的)上放置一个适当多国语言贮藏库元件,根据你自己的需要,如 TIniLanguageFileStorage 元件并设置好适当的属性(<TODO 需要扩展>)。
  39. 2).然后放上一个适当的多国语言管理器元件(通常是元件语言管理器:可以翻译元件和窗体的),并设置 DataStorage 属性为第一步的多国语言贮藏库元件。如果多国语言贮藏库元件也在同一窗体或模块上,多国语言管理器元件可以自动设置该属性(使用它找到的第一个多国语言贮藏库元件),用户可以不必操心。
  40. 在多国语言管理器元件双击即可调出多国语言管理器应用(第二阶段的事情[riceball]),等同于在元件上按下右键选择多国语言管理器菜单项。
  41. 3).放置翻译者元件到你想翻译的窗体上。当然不需要翻译者元件也可以完成翻译,只要在要翻译的窗体的 FormCreate 事件写一句:
  42. aLanguageManager.Translate(Self);
  43. 即可。
  44. 最好是建议使用窗体模板,只要使用(继承)该窗体模板的,都可以自动获得翻译能力,该窗体模板可以放到项目仓库中:
  45. TCustomTranslationForm = class(TForm)
  46. private
  47. protected
  48. procedure DoCreate; override;
  49. public
  50. procedure Translate; virtual;
  51. end;
  52. procedure TCustomTranslationForm.DoCreate;
  53. begin
  54. inherited;
  55. Translate;
  56. end;
  57. procedure TCustomTranslationForm.Translate;
  58. begin
  59. if Assigned(GLanguageManager)then
  60. GLanguageManager.Translate(Self);
  61. end;
  62. 在进一步,就是创建翻译项目向导(这是第二阶段考虑的事情了),建立项目。
  63. 在翻译者元件上双击将激活窗体翻译管理器(Form Translation Manager)。如果该窗体是第一次运行窗体翻译管理器,将列出该窗体上的所有元件以及对应需要显示的属性让你选择,那些需要翻译。否则直接开始窗体翻译。
  64. 在翻译者元件上单击右键,将弹出以下菜单:
  65. [&C]创建语言文件
  66. 分析窗体上所有的元件属性,创建指定的语言文件。如果该语言文件存在有用户决定是否覆盖或者更新。
  67. 由于第一阶段暂不实现窗体翻译管理器,所以该菜单才有存在的必要。
  68. [&U]更新语言文件
  69. 当你在窗体上添加了新元件后使用,更新指定的语言文件。
  70. [&T]窗体翻译管理器
  71. _____________________________________________________________________________
  72. China Pack - MultiLanguage Translation Component Packadge Requirement Specification
  73. By Riceball<riceball@cq118.com>
  74. Platform: D34567, C456, K123 above
  75. introduction:
  76. Main Purpose:
  77. the most simplify the translation of an application from one language to another without a great deal of programming(just put the MultiLanguage Translation Components on the form or DataModule, no extra programming needed), and switch between the languages instantly.
  78. 1. Kernel Components
  79. MultiLanguage Translation core Components are made up of the Language DataStorage Component, the Language Manager Component, the Translator Component.
  80. 1). Language DataStorage Components
  81. the Language DataStorage Components use to hold language strings which can be stored in Ini file , XML file, database, or internal EXE file.
  82. NOTE[riceball]:
  83. I. In the first phase we will implement the TIniLanguageFileStorage to hold language strings in Ini files. Of cause, u can develope ur own Language DataStorage Components(welcome to join us).
  84. II. Create New Language , Save Language, Set Current Language(Languages Files Manage) are here.
  85. The valid languages(translated) are accessible via the Languages and LanguageCount properties. The current language is accessible by the CurrentLanguage property.
  86. Components:
  87. * TCustomLanguageStorage (Abstract Class for the component developers.)
  88. * TCustomLanguageFileStorage(Abstract Class for the component developers.)
  89. * TIniLanguageFileStorage (for the component developers.)
  90. * TCnIniLanguageFileStorage (the Component on the Palette for users.)
  91. 2). Language Manager Components
  92. The Language Manager are the core components of the translation suite. This component has the ability to manage multiple languages.
  93. Double click on the Language Manager Component to show Language Manager application. Or right click on it , choose the Language Manager menu item.
  94. Note: One App must have one and only one TCustomLanguageManager instance!
  95. You can visit this instance via the GLanguageManager function.
  96. Components:
  97. * TCustomLanguageManager (Abstract Class for the component developers.)
  98. * TCnLanguageManager (the Component on the Palette for users.)
  99. * TCustomLanguageFormManager(for the component developers.)
  100. * TCnLanguageFormManager (the Component on the Palette for users.)
  101. 3). Translator Component
  102. This is the helper component of the translation suite to make translated language easy in Delphi IDE(for lazy men). U should put a translator component to the form u wanna translated(Only one translator per form).
  103. Components:
  104. * TCustomTranslator(for the component developers.)
  105. * TCnTranslator (the Component on the Palette for users.)
  106. 2. Usage:
  107. 1). put a proper Language DataStorage on the main form or a DataModule. And set the proper properties. <TODO Need Expand: How to set proper properties>
  108. 2). then put a proper Language Manager(we use the Component Language Manager generally , this can translate the Components and Forms) on the main form or a DataModule, assign the DataStorage property(if the Language DataStorage component is on the same Form or DataModule, it can automatically assign the DataStorage component to itself).
  109. 3). Put a translator component to the form u wanna translated. Or don't put the translator component , write the following code on the FormCreate Event instead:
  110. aLanguageManager.Translate(Self);
  111. [Suggestion] create a tranlation form template, u can inherit the form to get the translation ability:
  112. TCustomTranslationForm = class(TForm)
  113. private
  114. protected
  115. procedure DoCreate; override;
  116. public
  117. procedure Translate; virtual;
  118. end;
  119. procedure TCustomTranslationForm.DoCreate;
  120. begin
  121. inherited;
  122. Translate;
  123. end;
  124. procedure TCustomTranslationForm.Translate;
  125. begin
  126. if Assigned(GLanguageManager)then
  127. GLanguageManager.Translate(Self);
  128. end;
  129. Of cause u can create a translation Project wizards. this would be done on second phase.
  130. Double click on the translator component to active the Form Translation Manager.
  131. the Form Translation Manager let u choose which properties of these components on the form need be translated(first run). Or begin to translate online.
  132. Right click on the translator component to popup the menu :
  133. &Create Language files
  134. Create ur specified Language files. U can choose whether override the exists files.
  135. &Update Language files
  136. Update ur specified Language files when u add some new components on it.
  137. Form &Translation Manager