Cupertino Translation on Flutter

Muhammad Iqbal
2 min readJan 4, 2019

NOTE: This article is written at the time Flutter 1.9.1-hotfix is the recent stable version

Working on flutter been great for me. This also marks my first time working on iOS app development natively. But I found a problem when working on localization with Cupertino’s tooltip like this:

This happened when I set the device language to Bahasa (Indonesian) or anything aside default English then I tried to tap and hold on textField to bring up tooltip with Copy and Paste menu.

Searching on Github gave me to this issues (which still opened when I wrote this) :

Oh well, I could not do much and users are most likely trying to bring up that very tooltip on that screen. So I followed the advice from the issue and created my Cupertino translation for Bahasa.

I found Cupertino default localization for English from flutter (highlighted if you clicked from the link below:

Basically these are what I did when I need Cupertino tooltip in Bahasa :

  • I created new file → new class called CupertinoId based on DefaultCupertinoLocalizations , then translate everything to Bahasa
  • then created new _CupertinoLocalizationsDelegate on the very same file. Replace the language code with id inside this class.
@overridebool isSupported(Locale locale) => locale.languageCode == 'id';
@overrideString toString() => 'CupertinoId.delegate(id_ID)';
  • Still on _CupertinoLocalizationsDelegate , we want to loadCupertinoId created on first step when Bahasa is currently used on device locale
@overrideFuture<CupertinoLocalizations> load(Locale locale) =>CupertinoId.load(locale);
  • Add localization references and supported locales into mainMaterialApp, usually located in app.dart
MaterialApp(...localizationsDelegates: [  CupertinoId.delegate,  GlobalMaterialLocalizations.delegate,  GlobalWidgetsLocalizations.delegate,],
supportedLocales: [
const Locale('id', 'ID'),const Locale('en', 'US'),],...)
  • Don’t forget to add id language support on iOS Info.plist file
<dict>... <key>CFBundleLocalizations</key> <array>  <string>en</string>  <string>id</string>  </array>...</dict>

and you are set! 🍻

To create for another language, just repeat those steps with corresponding language ID and translation. Reminder that this just a quick fix (I’m not sure if this is the right way) until Flutter implement Cupertino translation.

This tooltip will refer to your device locale, should not be affected with selected app locale unless you made it so.

Thanks!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Responses (1)

Write a response

Can you provide the customized code for reference? Thanks a lot.

--