Cross Platform Localization Strategies

36

Transcript of Cross Platform Localization Strategies

Page 1: Cross Platform Localization Strategies
Page 2: Cross Platform Localization Strategies

@loriblalonde solola.ca

CTTDNUG

Me, Myself and I

Twitter: @loriblalonde

Email: [email protected]

Blog: solola.ca

Web: westerndevs.com

Page 3: Cross Platform Localization Strategies

@loriblalonde solola.ca

2

Page 4: Cross Platform Localization Strategies
Page 5: Cross Platform Localization Strategies
Page 6: Cross Platform Localization Strategies

@loriblalonde solola.ca

Appeal to a Broader Market

Shared App Logic in C#

*photo attribution: created by niroworld at fotolia (https://www.fotolia.com/id/66976406)

Page 7: Cross Platform Localization Strategies

@loriblalonde solola.ca

Shared App Logic in C#

*photo attribution: created by photosoup at fotolia (https://us.fotolia.com/id/61647429)

Page 8: Cross Platform Localization Strategies
Page 9: Cross Platform Localization Strategies
Page 10: Cross Platform Localization Strategies

@loriblalonde solola.ca

Xamarin Android String Resources

Strings stored in XML file(s) in values directory

Place XML files in values directory for each supported language code

Page 11: Cross Platform Localization Strategies

@loriblalonde solola.ca

Xamarin Android Image Resources

Images with text should be localized

Set Image BuildAction as AndroidResource

Place localized images in drawabledirectory for each supported language code and device resolution

Page 12: Cross Platform Localization Strategies

@loriblalonde solola.ca

Xamarin.Android: Accessing Resources

In layout file:Strings - @string/[id]

Images - @drawable/[id]

In code: textView.Text = Resources.GetString(Resource.String.greeting);

imageView.SetImageResource(Resource.Drawable.stopsign);

Page 13: Cross Platform Localization Strategies

@loriblalonde solola.ca

Xamarin iOS String Resources

Shared App Logic in C#

Strings stored in .strings files in .lprojdirectories

Base.lproj – default language

<languagecode>.lproj directory –supported language

.strings file format: “key” = “value”;

Page 14: Cross Platform Localization Strategies

@loriblalonde solola.ca

Xamarin iOS Image Resources

Shared App Logic in C#

Place localized images in respective .lproj directories

Set Image BuildAction as BundleResource

Page 15: Cross Platform Localization Strategies

@loriblalonde solola.ca

Xamarin.iOS: Accessing Resources

//app display namevar title = NSBundle.MainBundle

.ObjectForInfoDictionary("CFBundleDisplayName"); AppTitleLabel.Text = title.ToString();

//how to get the localized string in codeHelloLabel.Text = NSBundle.MainBundle.LocalizedString("hello", "comment");

//how to get localized image in codeStopImage.Image = UIImage.FromBundle("stopsign");

Page 16: Cross Platform Localization Strategies

@loriblalonde solola.ca

Escape Characters

Shared App Logic in C#

Android and iOS string resources must use the following escape characters:

\" quote

\\ backslash

\n newline

Page 17: Cross Platform Localization Strategies

@loriblalonde solola.ca

Universal Windows Platform (UWP) Resources

Resource file (.resw) localization

Compiled into the application package

Place resource files in named directory for each supported language code

Page 18: Cross Platform Localization Strategies

@loriblalonde solola.ca

Resw File Structure

Shared App Logic in C#

Name/Value pair. Optionally append a qualifier on key.

Qualifier represents the element property that will be set to the resource value

UWP supports translations for app display name and description

Page 19: Cross Platform Localization Strategies

@loriblalonde solola.ca

UWP: Accessing Resources

Shared App Logic in C#

In layout file:

Strings – set x:Uid of element to resource

Images – set source to path of default image

In code: var resourceLoader = new Windows.ApplicationModel.Resources.ResourceLoader();string res = resourceLoader.GetString("DisplayName");

Page 20: Cross Platform Localization Strategies

@loriblalonde solola.ca

Localizing Application Metadata

Shared App Logic in C#

Page 21: Cross Platform Localization Strategies

@loriblalonde solola.ca

Page 22: Cross Platform Localization Strategies

@loriblalonde solola.ca

Drawbacks

Shared App Logic in C#

Maintain separate set of resource files for each platform

Platform-specific code needed to access localized resources

Page 23: Cross Platform Localization Strategies
Page 24: Cross Platform Localization Strategies

@loriblalonde solola.ca

Leverage .NET Localization

Create a Portable Class Library that will contain the resource (.resx) files

Leverage ResourceManager to load the strings

Create a Translation Helper class to retrieve translations by language and key

Use Reflection to retrieve handle to Assembly

Page 25: Cross Platform Localization Strategies

@loriblalonde solola.ca

Resx File Structure

Shared App Logic in C#

Name/Value pair

Reference in code using ResourceManager

Can leverage data binding to retrieve translation

Page 26: Cross Platform Localization Strategies

@loriblalonde solola.ca

Page 27: Cross Platform Localization Strategies

@loriblalonde solola.ca

Supported across all platforms (iOS, Android, Windows)

Only 1 set of resource files to maintain

3rd party tools available such as ResX Manager, making it easy for translators to work with

Supported in Xamarin.Forms, with data binding support

Advantages

Page 28: Cross Platform Localization Strategies

@loriblalonde solola.ca

Drawbacks

Shared App Logic in C#

Application name will not be localized

Workaround: include native strings file in each language for the application name only

Page 29: Cross Platform Localization Strategies

@loriblalonde solola.ca

Download translations for the selected language from your own web service in JSON or XML format

Logic can be encapsulated in Portable Class Library

Deserialize result into a Translations collection (Key/Value pair) Use Reflection to retrieve handle to Assembly

Create a Translation Helper class to retrieve translations by language and key

Custom Web Service Provider

Page 30: Cross Platform Localization Strategies

@loriblalonde solola.ca

Supported across all platforms

Only download the translation file that is needed

Supported in Xamarin.Forms

c

Advantages

Page 31: Cross Platform Localization Strategies

@loriblalonde solola.ca

Drawbacks

Shared App Logic in C#

Application name will not be localized

Dependent on network connectivity when switching languages

Difficult for translators to work with JSON

Page 32: Cross Platform Localization Strategies
Page 33: Cross Platform Localization Strategies

@loriblalonde solola.ca

General Considerations

Shared App Logic in C#

Design your app to support multiple languages

Never hardcode strings

Store strings in language resource files

Avoid string concatenation

Ensure your UI is flexible to adapt to variable string length

Page 34: Cross Platform Localization Strategies
Page 35: Cross Platform Localization Strategies

@loriblalonde solola.ca

Additional Resources

Shared App Logic in C#

Xamarin Localization Documentation

iOS: http://bitly.com/XamiOSLocalization

Android: http://bitly.com/XamAndLocalization

Xamarin.Forms: http://bitly.com/XamFormsLocalization

Page 36: Cross Platform Localization Strategies

Twitter: @loriblalonde

Email: [email protected]

Blog: solola.ca

westerndevs.com

@westerndevs