Система Flash UI/Локализация UI

Материал из CryWiki Russia

(Различия между версиями)
Перейти к: навигация, поиск
(Новая страница: «<parsererror>Ошибка синтаксического анализа XML: несоответствующий тег. Ожидается: </table>. Адре...»)
Строка 1: Строка 1:
-
<parsererror>Ошибка синтаксического анализа XML: несоответствующий тег. Ожидается: &lt;/table&gt;. Адрес: http://wiki.crymod.net/index.php?title=%D0%A1%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_Flash_UI/%D0%9B%D0%BE%D0%BA%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F_UI&action=edit&redlink=1 Строка 138, символ 52:<sourcetext>&lt;div class="panelMacro"&gt;&lt;table class="infoMacro"&gt;&lt;/colgroup&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;img src="http://freesdk.crydev.net/images/icons/emoticons/information.gif" alt="" border="0" height="16" width="16" align="absmiddle"/&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Note&lt;/b&gt;&lt;br/&gt;If you use translation labels for static textboxes you have to make them dynamic! Otherwise the translation doesn't work.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; ---------------------------------------------------^</sourcetext></parsererror>
+
CryENGINE comes with a localization system that allows text localization for the UI. The [SDKDOC3:Localization] System is documented within the Asset Creation Manual.
 +
 
 +
Besides string localization it is also possible to use different font and glyph sets for each language.
 +
 
 +
== Basic folder structure ==
 +
{| class="crytable"
 +
! Folder !! Description
 +
|-
 +
| Game\Libs\UI\*.gfx || Flash assets
 +
|-
 +
| Game\Localized\<language>.pak\Libs\UI\gfxfontlib.gfx || Font lib for each language
 +
|-
 +
| Game\Localized\<language>.pak\Libs\UI\gfxfontlib_glyphs.gfx || Glyph set for each language
 +
|-
 +
| Game\Localized\<language>.pak\Languages\*.xml || Translation tables
 +
|}
 +
 
 +
== String Localization ==
 +
UI string translations are stored in xml excel sheets. It simply stores labels (keys) and translation.
 +
 
 +
== Translation table ==
 +
The UI translation tables are located under: {{Game\Languages.xml}}. The system loads all xml files in this folder on start-up or on language change.
 +
Translation tables for each language must be stored under: {{Game\Localized\<Language>.pak\Languages.xml}}.
 +
For UI translation the tables must have a column *"KEY"*, *"ORIGINAL TEXT"* and *"TRANSLATED TEXT"*.
 +
 
 +
!translation.png!
 +
 
 +
== Pass localized string at runtime ==
 +
A label is also translated if it is passed as string to a dynamic textfield via {{Code\FlowGraph\LUA}}.
 +
 
 +
{code:title=uielements.xml} <UIElement name="MyElement">
 +
 
 +
<GFx file=" MyElement.gfx" layer="2" alpha="1" >
 +
<Constraints>
 +
<Align mode="fullscreen" />
 +
</Constraints>
 +
</GFx>
 +
 
 +
<variables>
 +
<variable name=" MyTextbox " varname="_root.TextLayer.TextBox.text"/>
 +
</variables>
 +
 
 +
</UIElement>
 +
{code}
 +
 
 +
{code:title=cpp}IFlashUIPtr pFlashUI = GetIFlashUIPtr();
 +
If (pFlashUI)
 +
{
 +
IUIElement* pElement = pFlashUI->GetUIElement(“MyElement”);
 +
If (pElement)
 +
pUIElement->SetVariable(“MyTextbox”, SUIArguments(“@somelabel”));
 +
}
 +
{code}
 +
 
 +
== Fontlibs and glyph sets ==
 +
It is recommended to use *one* font library and glyph set for all flash assets. One reason is to save memory since you don’t want to embed every font in every flash file. This technique also allows embedding different glyph sets for different languages.
 +
 
 +
It also makes sure that your corporate design is consistent over all UI assets and changes are even easier since it is only necessary to change two files to switch the font for the whole UI.
 +
 
 +
=== Setup gfxfontlib and gfxfontlib_glyphs ====
 +
There are two files that are needed:
 +
 
 +
* gfxfontlib.gfx - Font library.
 +
* gfxfontlib_glyphs.gfx - Glyph set.
 +
 
 +
The *gfxfontlib.gfx* defines all your fonts that are used in your UI.
 +
 
 +
Since exported fonts in flash always hold every glyph for the chosen font it is necessary to create a *gfxfontlib_glyphs.gfx* file that allows embedding only the glyphs you want.
 +
 
 +
=== Setup gfxfontlib_glyphs.gfx ===
 +
This file holds every glyph for every font that is used in the UI.
 +
Create a new flash file and name it *gfxfontlib_glyphs.fla*.
 +
Create Dynamic Textboxes on the stage for each font and font-style and embed the needed characters.
 +
 
 +
!glyph_file_1.png!
 +
 
 +
Create an empty dummy MovieClip and mark it for “Export for runtime sharing”.
 +
 
 +
!glyph_file_2.png!
 +
 
 +
Export the gfxfontlib_glyphs.swf file with the following command:
 +
 
 +
{code}gfxexport.exe -c -i DDS -share_images -rescale hi gfxfontlib_glyphs.swf
 +
{code}
 +
 
 +
=== Setup gfxfontlib.gfx ===
 +
This file defines all fonts and font-styles for the UI.
 +
Create a new flash file and name it gfxfontlib.fla. Create new font symbols for each font and font-style in the library (*Right-Click -> New font*)
 +
Choose font and style, give it a name and mark “Export for runtime sharing”
 +
 
 +
!fontlib_1.png!
 +
 
 +
Create an empty MovieClip and mark it as “import for runtime sharing” (or just copy and paste the dummy MovieClip from the gfxfontlib_glyphs.fla). This step is necessary to create a dependency to the glyph file.
 +
 
 +
!fontlib_2.png!
 +
 
 +
Export the gfxfontlib.swf file with the following command:
 +
 
 +
{code}gfxexport.exe -c -i DDS -share_images -rescale hi -strip_font_shapes gfxfontlib.swf
 +
{code}
 +
 
 +
=== Import fonts to any flash asset ===
 +
Finally you need to import the exported fonts from gfxfontlib.gfx to your flash assets. You can just copy and paste them.
 +
 
 +
!flash_asset1.png!
 +
 
 +
Export your flash assets with the following command:
 +
 
 +
{code}gfxexport.exe -c -i DDS -share_images -rescale hi -strip_font_shapes *.swf
 +
{code}
 +
 
 +
To use the fonts on your textboxes just choose them in the font dropdown list.
 +
 
 +
!flash_asset2.png!
 +
 
 +
{info:title=Note}If you use translation labels for static textboxes you have to make them dynamic! Otherwise the translation doesn't work.{info}
 +
 
 +
== Different font libraries and glyph sets for different languages ==
 +
Just create *gfxfontlib.gfx* and *gfxfontlib_glyphs.gfx* files for each language and place them under:
 +
{{Game\Localized\<language>.pak\Libs\UI}}
 +
 
 +
{info:title=Note}You have to reload the UI elements after switching to a different language.{info}

Версия 16:31, 9 марта 2012

CryENGINE comes with a localization system that allows text localization for the UI. The [SDKDOC3:Localization] System is documented within the Asset Creation Manual.

Besides string localization it is also possible to use different font and glyph sets for each language.

Содержание

Basic folder structure

Folder Description
Game\Libs\UI\*.gfx Flash assets
Game\Localized\<language>.pak\Libs\UI\gfxfontlib.gfx Font lib for each language
Game\Localized\<language>.pak\Libs\UI\gfxfontlib_glyphs.gfx Glyph set for each language
Game\Localized\<language>.pak\Languages\*.xml Translation tables

String Localization

UI string translations are stored in xml excel sheets. It simply stores labels (keys) and translation.

Translation table

The UI translation tables are located under: Шаблон:Game\Languages.xml. The system loads all xml files in this folder on start-up or on language change. Translation tables for each language must be stored under: {{Game\Localized\<Language>.pak\Languages.xml}}. For UI translation the tables must have a column *"KEY"*, *"ORIGINAL TEXT"* and *"TRANSLATED TEXT"*.

!translation.png!

Pass localized string at runtime

A label is also translated if it is passed as string to a dynamic textfield via Шаблон:Code\FlowGraph\LUA.

{code:title=uielements.xml} <UIElement name="MyElement">

<GFx file=" MyElement.gfx" layer="2" alpha="1" > <Constraints> <Align mode="fullscreen" /> </Constraints> </GFx>

<variables> <variable name=" MyTextbox " varname="_root.TextLayer.TextBox.text"/> </variables>

</UIElement> {code}

{code:title=cpp}IFlashUIPtr pFlashUI = GetIFlashUIPtr(); If (pFlashUI) { IUIElement* pElement = pFlashUI->GetUIElement(“MyElement”); If (pElement) pUIElement->SetVariable(“MyTextbox”, SUIArguments(“@somelabel”)); } {code}

Fontlibs and glyph sets

It is recommended to use *one* font library and glyph set for all flash assets. One reason is to save memory since you don’t want to embed every font in every flash file. This technique also allows embedding different glyph sets for different languages.

It also makes sure that your corporate design is consistent over all UI assets and changes are even easier since it is only necessary to change two files to switch the font for the whole UI.

Setup gfxfontlib and gfxfontlib_glyphs =

There are two files that are needed:

  • gfxfontlib.gfx - Font library.
  • gfxfontlib_glyphs.gfx - Glyph set.

The *gfxfontlib.gfx* defines all your fonts that are used in your UI.

Since exported fonts in flash always hold every glyph for the chosen font it is necessary to create a *gfxfontlib_glyphs.gfx* file that allows embedding only the glyphs you want.

Setup gfxfontlib_glyphs.gfx

This file holds every glyph for every font that is used in the UI. Create a new flash file and name it *gfxfontlib_glyphs.fla*. Create Dynamic Textboxes on the stage for each font and font-style and embed the needed characters.

!glyph_file_1.png!

Create an empty dummy MovieClip and mark it for “Export for runtime sharing”.

!glyph_file_2.png!

Export the gfxfontlib_glyphs.swf file with the following command:

{code}gfxexport.exe -c -i DDS -share_images -rescale hi gfxfontlib_glyphs.swf {code}

Setup gfxfontlib.gfx

This file defines all fonts and font-styles for the UI. Create a new flash file and name it gfxfontlib.fla. Create new font symbols for each font and font-style in the library (*Right-Click -> New font*) Choose font and style, give it a name and mark “Export for runtime sharing”

!fontlib_1.png!

Create an empty MovieClip and mark it as “import for runtime sharing” (or just copy and paste the dummy MovieClip from the gfxfontlib_glyphs.fla). This step is necessary to create a dependency to the glyph file.

!fontlib_2.png!

Export the gfxfontlib.swf file with the following command:

{code}gfxexport.exe -c -i DDS -share_images -rescale hi -strip_font_shapes gfxfontlib.swf {code}

Import fonts to any flash asset

Finally you need to import the exported fonts from gfxfontlib.gfx to your flash assets. You can just copy and paste them.

!flash_asset1.png!

Export your flash assets with the following command:

{code}gfxexport.exe -c -i DDS -share_images -rescale hi -strip_font_shapes *.swf {code}

To use the fonts on your textboxes just choose them in the font dropdown list.

!flash_asset2.png!

{info:title=Note}If you use translation labels for static textboxes you have to make them dynamic! Otherwise the translation doesn't work.{info}

Different font libraries and glyph sets for different languages

Just create *gfxfontlib.gfx* and *gfxfontlib_glyphs.gfx* files for each language and place them under: {{Game\Localized\<language>.pak\Libs\UI}}

{info:title=Note}You have to reload the UI elements after switching to a different language.{info}