mvp virtual conference - americas 2015 - cross platform localization for mobile apps

51
Cross-Platform Localization for Mobile Apps Using .NET Chris Miller, Tyler Technologies James Montemagno, Xamarin May 15 th , 2015 May 14 – 15, 2015 2015 Microsof t MVP Virtual Conferen ce

Upload: christopher-miller

Post on 12-Aug-2015

273 views

Category:

Technology


0 download

TRANSCRIPT

Cross-Platform Localization for Mobile Apps Using .NETChris Miller, Tyler TechnologiesJames Montemagno, XamarinMay 15th, 2015

May 14 – 15, 2015

2015 Microsoft MVP Virtual Conference

Who we are : Chris Miller

Chris is a Senior R&D Engineer for Tyler Technologies, Currently working on mobile apps for the K-12 transportation market. He leads the Tech Valley .NET User Group in Albany, NY.

@anotherlabhttp://www.rajapet.com

Who we are: James Montemagno

James Montemagno is a Developer Evangelist at Xamarin. He has been a .NET developer for over a decade working in a wide range of industries including game development, printer software, and web services. Previously, James was a professional mobile developer on the Xamarin platform for over 3 years, with several published apps on iOS, Android, and Windows.

@JamesMontemagnohttp://motzcod.es/

What is localization?

Localization is the process that you follow to allow your web site or application to support multiple languages and locales.

Why should you localize your app?• Greater Exposure• Easy Deployment• Business or Legal requirements

Why should you localize your app?

Why should you localize your app?

Why should you localize your app?

Why should you localize your app?

Know the localization problem

• What are the localization requirements for your app?• How many languages do you need to support?• Do you need to use right-to-left languages like Arabic or

Hebrew?• Does your application have it's own or an industry

specific set of terminology?

Common terminology

Locale - The culture for the user

Language - The language used by the user. The same language in different countries can have different spelling and grammar rules.

Culture/UICulture - The .NET representation of a locale. Culture is the locale, UICulture the language.

Example Images

Stop Sign (USA) Stop Sign (France)

Example Images

• Stop Sign (Japan)

Gender

• English is usually gender neutral, other languages are not.

Plural Forms

• The common pattern in English is the singular/plural form• Asian languages typically use just a single from• French and Brazilian Portuguese use a different

singular/plural form.• Then it gets complicated. See https://

developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules for a long list of rules.

• Use the “Noun : Pattern” instead• New Messages: 1

The tools that I use

• Visual Studio 2013/2015• Xamarin (both on OS X and as a VS plugin)• Multilingual App Toolkit (MAT)

Create native iOS, Android, Mac andWindows apps in Visual Studio and

C#

About Xamarin

Xamarin’s Unique Approach

• Native User Interface• Native Performance• Shared code across

platforms• C# & .NET Framework• Full API Coverage

Xamarin’s Unique Approach

With Xamarin.Forms:

more code-sharing, native controls

Xamarin

First release ofXamarin.Mac

Launch PartnerProgram

200,000Developers

XamarinFounded

First release ofXamarin.Android

Xamarin.iOS launches (originally known as MonoTouch)

XimianFounded

Over a Decade of Enterprise Production Use

2001 2003 2009 2011 2012 2013

MonoLaunches

Ximian Acquiredby Novell

Xamarin 2.0

Component Store

Xamarin Test Cloud

Evolve 2013

Microsoft Partnership

500,000Developers100+ Partners100+ Components

2014

//

Xamarin 3

2000

SAP Partnership

Fire TV Support

Salesforce partnership

Visionary in Gartner Magic Quadrant

Google Glass Support

Visual Studio Partner of the Year

Android Wear Support

Xamarin Evolve 2014

800,000Developers200+ Partners200+ Components

Xamarin

• Provides a .NET development environment for C# and F# on iOS and Android.

• Supports PCL libraries and shared projects.• Compiles to native code and provides full access to

native APIs.• Xamarin.Forms provides an abstraction layer that lets

you write for that will compile and run as• Has a plugin for Visual Studio and their own IDE called

Xamarin Studio for Windows and OS X.• iOS development still requires an OS X machine for the

compilation and debugging.

Xamarin – Two Ways

• Xamarin.iOS and Xamarin.Android• Xamarin.Forms

How to manage the language files• Pick one application as the source for the string

resources. This works best for Xamarin.Forms applications. It can be done for Xamarin.Android and Xamarin.iOS but requires some extra work to generate the Android and iOS resource files from the Windows RESX files.

• Have app specific sets of resource files and use tooling to manage the language files.

Windows Store & Windows Phone

• We just need to create the .resx files for the locales to support and let the .NET Runtime do the heavy lifting.

• Use the Multilingual App Toolkit in Visual Studio to manage the resource files.

Xamarin.iOS

• Create the resource string files and put them in the proper location.

• File should be named Localizable.strings and placed in a folders for each language, with the folder name using the language code + .lproj. To localize the app name, set CFBundleDisplayNamein InfoPlist.strings– en.lproj for English– es.lproj for Spanish

• Prior to iOS 8, only the language code was supported. iOS 8 added support for locales.

Xamarin.iOS

• In Xamarin.iOS, we need to call LocalizedString, which maps to iOS’s localizedStringForKey method to do the language look up.

• That’s too much work.• Let’s add a string extension method to make it easy to

use.

Xamarin.iOS string extension

A helper class for setting the translated text

Xamarin.iOS string extension

Some examples…

Xamarin.Android

Create the default resource files, plus additional resources for each language supported. Strings, layouts, images, any resource can be localized.

While you can create alternate layouts for more verbose languages (e.g. German), this will make your app harder to maintain.

Converting RESX to iOS & Android

• iOS & Android use text files for string resources.– iOS uses flat text file– Android uses a XML format similar to RESX

• Use the same constants for each platform for shared resources.

We can convert this RESX file

To iOS/Android string resources

• iOS

• Android

Xamarin.Forms

• Single UI to target Android, iOS, and Windows Phone apps.

• Common set of controls that map to native controls at runtime.

• UI can be built from XAML markup or C# code.• Can be mixed with Xamarin.iOS & Xamarin.Android.

Multilingual App Toolkit

• Is XLIFF based, an industry standard file format for resource translations. Provides a basic audit trail of translated text values.

• Will make language specific versions of your string RESX files.

• Knows about Xamarin.iOS and Xamarin.Android and generates their string resource files.

• Can machine translate resource files using Bing.• Get it from https://

dev.windows.com/en-us/develop/multilingual-app-toolkit

Localization with Xamarin.Forms

• Not explicitly supported out of the box, but easy to implement.

• Xamarin has posted examples using RESX and Vernacular in their forums.

• Works great with Multilingual App Toolkit

Multilingual App Toolkit

• Enable MAT for the project from the Tools menu• Right-click on the project and select “Add translation

languages…”

Multilingual App Toolkit

• Double-click on a XLIFF to edit it

Multilingual App Toolkit

• Right-click on a project to machine translate the XLF files

Localization with Xamarin.Forms

• Move the AppResources.resx from Windows Phone project to shared PCL or create a new one in the PCL

• Create the localized versions of the RESX file with MAT• Create an IMarkupExtension to do translations in the

XAML

Getting the localized text in XAML

• Add your namespace• Use the databinding to call the markup converter

Getting the localized text in code behind• Just reference the resource file and resource id string

Right to Left (RTL) Support

• Target Android 4.2 or later.– add android:supportsRtl="true" to the <application>

element in your manifest file– Change all of your app's "left/right" layout properties to new

"start/end" equivalents

• iOS uses the Unicode Implicit Direction Mark Right-To-Left mark (#200F) to set RTL in the UILabel control as a string prefix.

• Windows Phone uses FlowControl property, set automatically by current culture.

• Xamarin.Forms does not have explicit support for RTL, it has to be done manually.

Demo Time

General Tips

• Do one platform a time and using tooling to transform the language resource files to the other platforms.

• Only do the languages that you need to do.• Use a fake language to test coverage and layout. Scott

Hanselman has a tool to create a fake language. (http://www.hanselman.com/blog/PsuedoInternationalizationAndYourASPNETApplication.aspx)

• Multilingual App Toolkit also generates a pseudo language.

General Tips

• To test different languages, set CurrentCulture and CurrentUICulture in code.

• If you change the language on the device, use an emulator. It’s not always easy to set the language back to your native choice.

• Language not showing up for Windows Phone? Make sure it’s checked of under Supported Cultures

• To localize the app & tile title for Windows Phone you need to create a separate resource dll. See https://msdn.microsoft.com/library/windows/apps/ff967550%28v=vs.105%29.aspx

• To localize the launcher name in Android, you will need to use strings.xml in Resources\values-xx-XX

General Tips

• Send the RESX or XLF to a commercial translation service.

• Hire someone to translate the resource files. Make sure that they understand the domain and industry standard terms.

• If you can't afford a paid translation, Bing translate basic terminology and crowd source it. Remember, you get what you pay for.

General Tips

• If you are using 3rd party components, make sure that they can be localized.

• Make sure to translate App Store text.

Thank You! …Questions?

The sample code from this presentation can be found onhttps://github.com/anotherlab/TheDoctors

Chris Miller can be reached via@anotherlabhttp://www.rajapet.com

James Montemagno can be reached via@JamesMontemagnohttp://motzcod.es/

Resources - Multilingual App Toolkit• Blog

http://blogs.msdn.com/b/matdev/• User Voice

http://multilingualapptoolkit.uservoice.com/• Installation

https://dev.windows.com/en-us/develop/multilingual-app-toolkit