2016年2月28日 星期日

Localization and Translate and RTL

Localization

the guide:


1.design the languahe and the 地區
2.have a flexibility UI, can expand horizontaly or vertically(30%),it is becuase different language have different size
or
have a different for different language,but this will more difficult to handle.


3.Handle the RTL and LTR


Format the date

How to get the current  Date in android?
1 get the calcender object
Calendar rightNow = Calendar.getInstance()


which include the current date and time


2.get the getTimeInMillis()
long l=rightNow.getTimeInMillis()


3.format it to the user's locale settings


android.text.format.DateFormat.getDateFormat().format(new Date(cursor.getString(columnIndex)))


Format the time

CharSequence fTime = DateUtils.formatDateTime(this,time,DateUtils.FORMAT_SHOW_TIME);


control what to show:
http://developer.android.com/intl/zh-tw/reference/android/text/format/DateUtils.html#formatDateRange(android.content.Context, java.util.Formatter, long, long, int, java.lang.String)



How to set RTL?

normal is LTR


step1
add android:supportsRtl="true" to the <application> element in your manifest file.


step2


in the layout(control the view LTR or RTL) :
need to have


android:layout_gravity="left"
replcae by
android:layout_gravity="start"


android:layout_gravity="right"
replcae by
android:layout_gravity="end"


if have android:layout_marginRight="0dp"
need add
android:layout_marginEnd="0dp"


if have android:layout_marginLeft="0dp"
need add
android:layout_marginStart="0dp"


if have(margin is same)
android:paddingRight="@dimen/activity_horizontal_margin"
add
android:paddingEnd="@dimen/activity_horizontal_margin"


if have(margin is same)
android:paddingLeft="@dimen/activity_horizontal_margin"
add
android:paddingStart="@dimen/activity_horizontal_margin"


and any other thing that have left and right is the same

and textview(control the view LTR or RTL)
same above


If you are targeting your app to Android 4.2 (the app's targetSdkVersion or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”. For example, android:paddingLeft should become android:paddingStart.


If you want your app to work with versions earlier than Android 4.2 (the app's targetSdkVersion or minSdkVersion is 16 or less), then you should add “start” and end” in addition to “left” and “right”. For example, you’d use both android:paddingLeft and android:paddingStart.


Translate:
we need to move all had code string to the xml
if the string should not translate should add
translatable="false"


if in a string anloy part of it no translate,should use
<xliff:g
example:the URI sholud not be translate
<string name="app_homeurl">


   Visit us at <xliff:g id="application_homepage">http://my/app/home.html</xliff:g>


</string>


more information about translate


after locallization,we need to give the local people to see