カテゴリー
Uncategorized

FlutterのCupertinoTimerPickerを日本語化する

何も考えずにCupertinoTimePickerを追加すると、端末の言語設定に関わらず、英語表記になってしまいます。

Widgetのプロパティでどうにかできると思いきやそのような機能は提供されていませんでした。いろいろ調べた結果、Flutterアプリケーションの多言語化対応が必要でした。

まず、Flutter公式のflutter_localizationsプラグインをインストールします。公式プラグインは、pub.devで提供されるのではなく、Flutter内部に内包されているようです。https://github.com/flutter/flutter/tree/master/packages/flutter_localizations

pubspecにプラグインを追記します。

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

main.dartでMaterialAppを使用しているので、ここでlocalizationsDelegatesとsupportedLocalesプロパティを追記します。

return MaterialApp(
  localizationsDelegates: [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  supportedLocales: [
    Locale('English'),
    Locale('ja')
  ],
  title: 'xxx',
  home: HomeScreen(title: "xxx"),
  //...
);

最後に、iOSアプリで使用するためにInfo.plistに対応言語を追記します。XCodeでInfo.plistを開きます。

  1. Information Property ListLocalizationsを追加
  2. ValueにJapaneseEnglishを追加

結果、このようになりました!(結構苦労しました…)

「FlutterのCupertinoTimerPickerを日本語化する」への1件の返信

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です