loctool for Android devs
loctool have plugin for android localization. ilib-loctool-android-resource and iilb-loctool-android-layout. loctool handles text string resources.
ilib-loctool-android-resource is for strings.xml file under res/values
,
ilib-loctool-android-layout plugin handles text in layout file under res/layout
Input file type | Output file type | Sample |
---|---|---|
xml | xml | here |
1) Extract localizable Strings
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings:
- String resource
- String
- String Array
- Quantity Strings (Plurals)
- Layout resource
a) String
<?xml version="1.0" encoding="utf-8"?><resources><string name="hello_world">Hello World!</string></resources>
b) String-array
<?xml version="1.0" encoding="utf-8"?><resources><string-array name="string_array_name"><item>text_string</item></string-array></resources>
c) Quantity strings (plurals)
<?xml version="1.0" encoding="utf-8"?><resources><plurals name="plural_name"><itemquantity=["zero" | "one" | "two" | "few" | "many" | "other"]>text_string</item></plurals></resources>
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"><RelativeLayout android:layout_width="match_parent"><com.mycompany.customviews.RobotoRegularTextViewandroid:id="@+id/invalidpasswordMsg"android:text="This is a test"android:textColor="@color/error_red"/></RelativeLayout></FrameLayout>
2) Prepre XLIFF files
Prepare multi-language XLIFF files with translation.
With loctool parameter or through a config file, It can set xliff files location.
// a) loctool option-x or --xliffsSpecify the dir where the xliffs files live. Default: "."// b) set in project.json config file..."settings": {"xliffsDir": "./xliffs",...
3) Write config file for loctool
Make sure resourceDirs
, resourceFileType
and plugin
are written correctly in config file.
i.e) project.json
..."resourceDirs": {"java":"res"},"resourceFileTypes": {"java":"ilib-loctool-android-resource"},"plugins": ["ilib-loctool-android-resource","ilib-loctool-android-layout"],...
4) Run the loctool - Generate localization data
loctool creates a new folder under res
with name of values-local
which follows androld localization rules.
i.e) Spanish strings (es locale), /values-es/strings.xml:
<resources><string name="hello_world">¡Hola Mundo!</string></resources>