GithubHelp home page GithubHelp logo

long1eu / flutter_i18n Goto Github PK

View Code? Open in Web Editor NEW
252.0 14.0 55.0 24.68 MB

This plugin create a binding between your translations from .arb files and your Flutter app.

License: Apache License 2.0

Java 1.66% Kotlin 29.16% HTML 0.22% Objective-C 0.14% Dart 68.50% Shell 0.32%
flutter-plugin flutter-apps i18n flutter-i18n flutter flutter-localization intellij-plugin arb arb-files flutter-examples

flutter_i18n's Introduction

PROJECT MAINTENANCE PAUSED

This project is no longer maintained due to the lack of time and availability. I'm a developer to and I know how frustrating can be when a tool I use no is no longer available or doesn't work any more. I'm sorry for the pain I've caused. :( Still in this repo the is a CLI tool that can work without the help of the IDE, and uses pure Dart to generate files in the same format. https://github.com/long1eu/flutter_i18n/tree/master/flutter_l10n Please give it a try, maybe it can ease your pain.

As of today I requested Intellij to remove the plugin from the market. Thanks for all the support.

Synopsis

This plugin helps you internationalize you Flutter app by generating the needed boiler plate code. You just add and organize strings in files that are contained in the /res/values folder. This plugin is based on the Internationalizing Flutter Apps tutorial and on the Material Library Localizations package. Much of the instructions are taken from there.

Usage

1. Setup you App

Setup your localizationsDelegates and your supportedLocales which allows the access to the internationalized strings.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      onGenerateTitle: (BuildContext context) => S.of(context).app_name,
      localizationsDelegates: const <LocalizationsDelegate<WidgetsLocalizations>>[
            S.delegate,
            // You need to add them if you are using the material library.
            // The material components usses this delegates to provide default 
            // localization      
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,               
      ],
      supportedLocales: S.delegate.supportedLocales,
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

Optionally, you can provide a fallback Locale for the unsupported languages in case the user changes the device language to an unsupported language. The default resolution is:

  1. The first supported locale with the same Locale.languageCode.
  2. The first supported locale.

If you want to change the last step and to provided a default locale instead of choosing the first one in you supported list, you can specify that as fallows:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      localizationsDelegates: [
            S.delegate,
            // You need to add them if you are using the material library.
            // The material components usses this delegates to provide default 
            // localization 
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,

      localeResolutionCallback:
          S.delegate.resolution(fallback: const Locale('en', '')),
      // this is equivalent to having withCountry: false, as in the next call:
      localeResolutionCallback:
          S.delegate.resolution(fallback: const Locale('en', ''), withCountry: false),

      // - OR -

      localeListResolutionCallback:
          S.delegate.listResolution(fallback: const Locale('en', '')),    
      // this is equivalent to having withCountry: false, as in the next call:
      localeListResolutionCallback:
          S.delegate.listResolution(fallback: const Locale('en', ''), withCountry: false),

      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

2. Setup the arb files.

ARB files extension stands for Application Resource Bundle which is used by the Dart intl package. ARB files are supported by the Google Translators Toolkit, thus supported by Google.

Flutter internalization only depends on a small subset of the ARB format. Each .arb file contains a single JSON table that maps from resource IDs to localized values. Filenames contain the locale that the values have been translated for. For example, material_de.arb contains German translations, and material_ar.arb contains Arabic translations. Files that contain regional translations have names that include the locale's regional suffix. For example, material_en_GB.arb contains additional English translations that are specific to Great Britain.

The first English file is generated for you(/res/values/strings_en.arb). Every arb file depends on this one. If you have a string in the German arb file(/res/values/strings_de.arb) that has an ID which is not found in the English file, it would not be listed. So you must be sure to first have the strings in the English file and then add other translations.

To add a new arb file right click on values folder and select New -> Arb File. Then pick your language from the list, and region if necessary.

1. Referencing the values

The ARB table's keys, called resource IDs, are valid Dart variable names. They correspond to methods from the S class. For example:

Widget build(BuildContext context) {
  return new FlatButton(
    child: new Text(
      S.of(context).cancelButtonLabel,
    ),
  );
}

2. Parameterized strings

Some strings may contain $variable tokens which are replaced with your values. For example:

{   
    "aboutListTileTitle": "About $applicationName"  
}

The value for this resource ID is retrieved with a parameterized method instead of a simple getter:

S.of(context).aboutListTileTitle(yourAppTitle)

3. Plurals

Plural translations can be provided for several quantities: 0, 1, 2, "few", "many", "other". The variations are identified by a resource ID suffix which must be one of "Zero", "One", "Two", "Few", "Many", "Other" (case insensitive). The "Other" variation is used when none of the other quantities apply. All plural resources must include a resource with the "Other" suffix. For example the English translations ('material_en.arb') for selectedRowCountTitle in the Material Library Localizations are:

{
    "selectedRowCountTitleZero": "No items selected",
    "selectedRowCountTitleMany": "to many items", //not actual real
    "selectedRowCountTitleOne": "1 item selected",
    "selectedRowCountTitleOther": "$selectedRowCount items selected",</pre>
}

Then, we can reference these strings as follows:

S.of(context).selectedRowCountTitle("many")

or

S.of(context).selectedRowCountTitle("1")

or

S.of(context).selectedRowCountTitle("$selectedRowCount")

3. Turning off the plugin per project.

With the release of v1.1.0 of the plugin, it is possible to turn on or off the plugin per project by adding a new top-level configuration option in your project's pubspec.yaml file: flutter_i18n

The plugin will be turned off by default for Dart-only projects, and on by default for Flutter projects. To change this setting, however, you have two options under the top-level flutter_i18n configuration:

enable-flutter-i18n: true / false

To activate the plugin for a Flutter project. The default setting is true.

enable-for-dart: true / false

To activate the plugin for a Dart-only project. The default setting is false.

NOTES:

  • The plugin also supports ${variable} notation. Use this when the parser does not catch the parameters properly. For example:

    {"tabLabel": "탭 $tabCount개 중 $tabIndex번째"}

    generates

    String tabLabel(String tabCount개, String tabIndex번째) => "탭 $tabCount개 중 $tabIndex번째";

    Which contains invalid Dart fields. In this case you should use

    {"tabLabel": "탭 ${tabCount}개 중 ${tabIndex}번째"}
  • Also you can escape the $ sign with \

    {"checkout_message": "You have to pay \$$price"}

Issues

There are some performance improvements and bug fixes that this plugin could use, so feel free to PR.

flutter_i18n's People

Contributors

artiomlk avatar long1eu avatar mormih avatar noordawod avatar wrozwad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_i18n's Issues

Error extracting string resource

When I try to use 'Extract string resource', I get the following error:

kotlin.KotlinNullPointerException
	at eu.long1.flutter.i18n.uipreview.DialogWrapper$Companion$showAndCreateFile$2$1.run(DialogWrapper.kt:50)
	at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:363)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:124)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:264)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1057)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:263)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:321)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:188)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:323)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:262)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:244)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:126)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:363)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:355)
	at eu.long1.flutter.i18n.uipreview.DialogWrapper$Companion$showAndCreateFile$2.run(DialogWrapper.kt:44)
	at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:435)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:419)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:403)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:719)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:668)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:363)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

IntelliJ 2018.3

Any ideas, when clicking the ARB icon in the toolbar.

Added the misc.xml file to the .idea directory and get result below.

kotlin.KotlinNullPointerException
	at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:42)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:64)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:963)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:150)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)

colliding arb keys with dart language

if you put as a key in the arb file one of the following values:

  • with
  • new
  • other
  • do

the generated class will no longer compile, quick workaround for this would be to put trailing underscore

Key based get

Hi, would it be possible to have something like S.get(key) ? I would like to associate a list of settings keys with displayable strings.
Today I have to have a switch for each key, which it not very developer friendly.

Localizations no longer works after upgrade to the latest version of flutter i18n plugin

Hi to all,
on a my Flutter app I use the flutter i18n plugin for texts localizations, with two supported languages: Italian and English (the English is also the fallback language). This localizations until a few days ago worked properly, but after the upgrade of the i18n plugin to the latest version 0.1.1 it stopped working, and all the app's texts are now always displayed in English (the fallback language ) even if on my Android device the language is set to Italian ('it'), and before this upgrade the texts were correctly localized in Italian.

I did not change anything in the code, but I realized that now, if I call (for test) Localizations.localeOf (context), it always returns the 'en_' Locale, even if on the device I set the French language or Italian language, or any other language other than English.

This is clearly a mistake. I'm not sure, but I think this error came out after upgrading to version 0.1.1 of the flutter i18n plugin in my Android Studio (version 3.2.1) development environment.

Steps to Reproduce

This is the interestings code:

@override
  Widget build(BuildContext context) {
    Locale currentLocale = Localizations.localeOf(context);
    String localizationLanguageCode = S.delegate.isSupported(currentLocale) ? currentLocale.languageCode : Config.defaultLanguageCode;
    print('currentLocale is: ${currentLocale.toString()}, currentLocale.languageCode is: ${currentLocale.languageCode}, localizationLanguageCode is: $localizationLanguageCode');
    return MaterialApp(
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,
      localeResolutionCallback: S.delegate.resolution(fallback: new Locale('${Config.defaultLanguageCode}', '')),
      home: Scaffold(
        appBar: _makeAppBar(context),
        body: FutureBuilder<List<Lesson>>(
          future: fetchLessons(http.Client(), selectedCourse, localizationLanguageCode),
          //future: listLessons,
          builder: (context, snapshot) {
            this.numBuild++;
            print('number of build of LessonsRoute: ${this.numBuild}...');
            if (snapshot.hasError)  {
              print('Snaphot has the following error: ${snapshot.error}');
              return Center(
                  child: Text('Snaphot has the following error: ${snapshot.error}')
              );
            } else {
              if (snapshot.hasData) {
                if (snapshot.data != null && courses != null) {
                  return ListViewLessons(lessons: snapshot.data, courses: courses);
                } else {
                  return Center(child: Text('snapshot.data is null or/and courses is null!'));
                }
              } else {
                return Center(child: CircularProgressIndicator());
              }
            }
          },
        ),
      ),
    );
  }

In the above code, the following test instructions:

 Locale currentLocale = Localizations.localeOf(context);
 String localizationLanguageCode = S.delegate.isSupported(currentLocale) ? currentLocale.languageCode : Config.defaultLanguageCode;
 print('currentLocale is: ${currentLocale.toString()}, currentLocale.languageCode is: ${currentLocale.languageCode}, localizationLanguageCode is: $localizationLanguageCode');

Produces the following result:
`I/flutter ( 4432): currentLocale is: en_, currentLocale.languageCode is: en, localizationLanguageCode is: en

But, on my device (Samsung Galaxy S5 with Android 6.0.1) the language is set to Italian, not to English! See attached screenshots. Even with the ADVs emulators, I now have the same problem.

So, it seems that some internal i18n call to Localizations.localeOf (context) or similar, returns now a wrong result (always English Locale), which prevents localizations in other languages.

What happened? How can I make the localizations of texts on my app work again?

Also, referring to (flutter/flutter#24747) might help which probably explains what broke flutter_i18n?

Thanks in advance for the help you want to give me.

Flutter Doctor

[v] Flutter (Channel beta, v0.11.9, on Microsoft Windows [Versione 10.0.17134.407], locale it-IT)
    • Flutter version 0.11.9 at c:\src\flutter
    • Framework revision d48e6e433c (2 days ago), 2018-11-20 22:05:23 -0500
    • Engine revision 5c8147450d
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[v] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\lucio\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[v] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin version 30.0.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[v] Connected device (1 available)
    • SM G900F • 5fe4af7d • android-arm • Android 6.0.1 (API 23)

• No issues found!

flutter_02

The getter '{string_key}' was called on null.

static S of(BuildContext context) => Localizations.of<S>(context, S); ,
this call returns null
so the usage like will produce the exception The getter '{string_key}' was called on null.

Getting error in Plugin, studio doesn't recognize arb file.

Hi to all,
I 'm getting following error when my android studio is started, And studio doesn't recognize arb file.

java.lang.ClassCastException: com.intellij.psi.impl.file.PsiBinaryFileImpl cannot be cast to com.intellij.json.psi.JsonFile
at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:34)
at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:64)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945)
at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:150)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

Flutter Doctor

  • [✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G65, locale - zh-Hans-CN)
  • [✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
  • [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
  • [✓] Android Studio (version 3.3)
  • [✓] VS Code (version 1.31.1)
  • [✓] Connected device (2 available)

• No issues found!

MaterialLocalizations error

flutter/flutter@9bf8502

Since this commit, when multilingualization is done, the application spits out an error.

I/flutter ( 9104): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 9104): The following assertion was thrown building AppBar(dirty, state: _AppBarState#4c5fd):
I/flutter ( 9104): No MaterialLocalizations found.
I/flutter ( 9104): AppBar widgets require MaterialLocalizations to be provided by a Localizations widget ancestor.
I/flutter ( 9104): Localizations are used to generate many different messages, labels,and abbreviations which are used
I/flutter ( 9104): by the material library. 
I/flutter ( 9104): To introduce a MaterialLocalizations, either use a  MaterialApp at the root of your application to
I/flutter ( 9104): include them automatically, or add a Localization widget with a MaterialLocalizations delegate.
I/flutter ( 9104): The specific widget that could not find a MaterialLocalizations ancestor was:
I/flutter ( 9104):   AppBar
I/flutter ( 9104):   LayoutId-[<_ScaffoldSlot.appBar>](id: _ScaffoldSlot.appBar)
I/flutter ( 9104): 
I/flutter ( 9104): When the exception was thrown, this was the stack:
I/flutter ( 9104): #0      debugCheckHasMaterialLocalizations.<anonymous closure> (package:flutter/src/material/debug.dart:124:7)
I/flutter ( 9104): #1      debugCheckHasMaterialLocalizations (package:flutter/src/material/debug.dart:127:4)
I/flutter ( 9104): #2      _AppBarState.build (package:flutter/src/material/app_bar.dart:336:12)
I/flutter ( 9104): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:3766:27)
I/flutter ( 9104): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3678:15)

File generator does not work

Just installed plugin. The standard arb file was generated and I have the commands for extracting strings to arb.

But the i18n.dart file never gets generated: StackTrace:
kotlin.KotlinNullPointerException
at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:20)
at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:53)
at eu.long1.flutter.i18n.actions.RebuildI18nFile$actionPerformed$1.run(RebuildI18nFile.kt:13)
at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:364)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:124)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:265)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1038)
at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:264)
at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:322)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:139)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:107)
at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:324)
at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:262)
at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:244)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:126)
at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:364)
at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:356)
at eu.long1.flutter.i18n.actions.RebuildI18nFile.actionPerformed(RebuildI18nFile.kt:13)
at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:255)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:272)
at com.intellij.openapi.actionSystem.impl.ActionButton.actionPerformed(ActionButton.java:204)
at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:146)
at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:391)
at java.awt.Component.processEvent(Component.java:6313)
at java.awt.Container.processEvent(Container.java:2237)
at java.awt.Component.dispatchEventImpl(Component.java:4903)
at java.awt.Container.dispatchEventImpl(Container.java:2295)
at java.awt.Component.dispatchEvent(Component.java:4725)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
at java.awt.Container.dispatchEventImpl(Container.java:2281)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4725)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:737)
at java.awt.EventQueue$4.run(EventQueue.java:735)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:781)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:718)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Can't resolve string value resource

This plugin of Flutter is awesome! But I have encountered the issue that when I have added more string to the arb files, the i18n.dart is not re-generated automatically. How can I trigger it manually?

I'm using Android Studio 3.2

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.11.12, on Mac OS X 10.14.1 18B75, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
[✓] Android Studio (version 3.0)

The plugin version

The plugin version of android studio is still 0.0.6+1, how to update to the latest version?

Issue with Android Studio: Write access is allowed inside write-action only

Got this exception on a project without fiddling with misc.xml or anything else. Just installed the plugin and the error popped out.

Android Studio 3.3.1
Build #AI-182.5107.16.33.5264788, built on January 28, 2019
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.3

java.lang.Throwable: Assertion failed: Write access is allowed inside write-action only (see com.intellij.openapi.application.Application.runWriteAction()) at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:169) at com.intellij.openapi.application.impl.ApplicationImpl.assertWriteAccessAllowed(ApplicationImpl.java:1345) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.processEvent(PersistentFSImpl.java:686) at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.createChildFile(PersistentFSImpl.java:450) at com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry.createChildData(VirtualFileSystemEntry.java:217) at com.intellij.openapi.vfs.VirtualFile.findOrCreateChildData(VirtualFile.java:322) at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:23) at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:54) at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:64) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945) at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:150) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)

Edit to fix formatting.

i18n icelandic causes build issues

From @zoechi on December 11, 2018 18:6

@gardyna commented on Tue Dec 11 2018

adding Icelandic to internationalization creates the class "is" in i18n.dart which conflicts with a reserved keyword an causes any build to fail. I suggest changing it to isl (if possible) to avoid name conflicts or making some "default addition" to class names in i18n like and underscore or "lang_" to avoid future name confilct in i18n.


@zoechi commented on Tue Dec 11 2018

Where does the i18n.dart file come from? What method of adding i18n are you referring to?


@gardyna commented on Tue Dec 11 2018

When opening the project in android studio on mac I was prompted whether I wanted to add internationalization to the project. I clicked "yes" which added "res/values/strings_en.arb" and "lib/generated/i18n.dart" and get the suggestion to extract string resource. That wizard also allows me to add languages/regions. after finding Icelandic and adding it "res/values/strings_is.arb" appears along with additional code in i18n.dart (which causes the error)

attached is image of the wizard. I was under the assumption that this was an official addition to the dev-kit
image


@zoechi commented on Tue Dec 11 2018

@gardyna thanks for the update. I never used this assistant and wasn't aware of this feature.

Copied from original issue: flutter/flutter-intellij#2945

How to write a test for flutter_i18n

Is it possible to write tests when using this library? I've tried a few different ways of building the test widget, but I always get the same error message.

strings_en.arb

{
  "login": "LOGIN"
}

i18n_test.dart

import 'package:ad_mobile_flutter/generated/i18n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

class TestWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "test",
      localizationsDelegates: [S.delegate],
      supportedLocales: S.delegate.supportedLocales,
      localeResolutionCallback: S.delegate.resolution(fallback: new Locale("en", "")),
      locale: new Locale("en", ""),
      home: Scaffold(
        body: Container(
          child: Text(S.of(context).login),
          key: Key('login'),
        ),
      ),
    );
   }
}

void main() {
  testWidgets('locale test', (WidgetTester tester) async {
    await tester.pumpWidget(TestWidget());
  });
}

This results in:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building TestWidget(dirty):
The getter 'login' was called on null.
Receiver: null
Tried calling: login

When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
#1      TestWidget.build (file:///Users/jmj/Documents/Development/level11/ad_mobile_flutter/test/i18n_test.dart:17:37)
#2      StatelessElement.build (package:flutter/src/widgets/framework.dart:3695:28)
#3      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3642:15)
#4      Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5)
#5      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5)
#6      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5)
#7      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14)
[38 more...]
════════════════════════════════════════════════════════════════════════════════════════════════════

How to change language promatically

I use this plug-in can change language when app start-up.

But if I want to change language programmatically, who to do so.

ex: change language when I click a button.

thanks a lot :)

i18n error after IntelliJ 2018.2.2 CE Upgrade

After upgrading IntelliJ to 2018.2.2 loading the project results in a crash.

IntelliJ IDEA 2018.2.2 (Community Edition)
Build #IC-182.4129.33, built on August 21, 2018
JRE: 1.8.0_152-release-1248-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling.
	at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:57)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: rx.exceptions.OnErrorNotImplementedException: kotlin.KotlinNullPointerException
	at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:386)
	at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
	at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
	at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
	at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
	at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:212)
	at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139)
	at rx.internal.operators.OnSubscribeTimerPeriodically$1.call(OnSubscribeTimerPeriodically.java:52)
	at rx.internal.schedulers.SchedulePeriodicHelper$1.call(SchedulePeriodicHelper.java:72)
	at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189)
	at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
	... 7 more
Caused by: java.lang.RuntimeException: kotlin.KotlinNullPointerException
	at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:176)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:248)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:126)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:364)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:356)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$2.call(Initializer.kt:59)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$2.call(Initializer.kt:29)
	at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.java:39)
	at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
	... 11 more
Caused by: kotlin.KotlinNullPointerException
	at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:20)
	at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:51)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$2$1.run(Initializer.kt:60)
	at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:364)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:124)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:265)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1038)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:264)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:322)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:139)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:107)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:324)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:262)
	at com.intellij.openapi.command.WriteCommandAction.lambda$execute$0(WriteCommandAction.java:248)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransactionAndWait$2(TransactionGuardImpl.java:165)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:447)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:431)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:415)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:781)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:722)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

doesn't handle locales without regions very well

currently i'm using the library with only the language code without the country code
library generates the i18n file as follows

image

currently flutter for some reason when using a locale with a language code and an empty country code results in creating a locale languageCode_countryCode
so when creating Locale("ar,"") it gives ar_
and when using that locale with the material localizations it's says it's not supported
and that crashes the app when using it on ios specifically when long pressing a textfield to show the interactive selection menu as it can't translate the texts
tl;dr when creating the Locale in the supported locales it should be Locale("ar",null)
if the locale doesn't have a country

NullPointer at eu.long1.flutter.i18n.inspections.CreateStringInspector.checkFile(CreateStringInspector.kt:22)

kotlin.KotlinNullPointerException
	at eu.long1.flutter.i18n.inspections.CreateStringInspector.checkFile(CreateStringInspector.kt:22)
	at com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool$1.visitFile(AbstractBaseJavaLocalInspectionTool.java:70)
	at com.intellij.extapi.psi.PsiFileBase.accept(PsiFileBase.java:70)
	at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:75)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitRestElementsAndCleanup$4(LocalInspectionsPass.java:299)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:133)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1156)
	at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
	at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:116)
	at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:222)
	at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.pollAndExecCC(ForkJoinPool.java:1190)
	at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1879)
	at java.util.concurrent.ForkJoinPool.awaitJoin(ForkJoinPool.java:2045)
	at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:390)
	at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
	at java.util.concurrent.ForkJoinPool.invoke(ForkJoinPool.java:2616)
	at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:65)
	at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:56)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.visitRestElementsAndCleanup(LocalInspectionsPass.java:310)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:221)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:121)
	at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:83)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:69)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:423)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1161)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:416)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:415)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:391)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:222)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:389)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:161)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Cannot escape dollar($) sign

In the .arb file I added a string:
"test": "In my wallet I have \$10",
In the i18n.dart file that gets generated to:
String test(String 10) => "In my wallet I have \$10";
So it creates a parameter for the $ dollar sign but I actually want the $ sign to be part of my String. It is not escaping it.

Flutter change breaks LocaleResolutionCallback

I started seeing errors when trying to run on iOS.

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(IconThemeData#2abdc(color:
Color(0xdd000000))):
The getter 'languageCode' was called on null.
Receiver: null
Tried calling: languageCode

When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
#1      GeneratedLocalizationsDelegate.resolution.<anonymous closure> (package:americandream/generated/i18n.dart:99:55)
#2      _WidgetsAppState._resolveLocale (package:flutter/src/widgets/app.dart:682:36)
#3      _WidgetsAppState.initState (package:flutter/src/widgets/app.dart:566:15)
#4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3791:58)
#5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3657:5)
#6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2936:14)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

See these issues:
flutter/flutter#24064
flutter/flutter#24288

I was able to workaround this issue:

  1. Disable the flutter_i18n plugin in Android Studio
  2. Updated the resolution({Locale fallback}) function in my generated/i18n.dart file like so:
  LocaleResolutionCallback resolution({Locale fallback}) {
    return (Locale locale, Iterable<Locale> supported) {

      if (locale == null || !isSupported(locale) ) {
        final Locale fallbackLocale = fallback ?? supported.first;
        return fallbackLocale;
      }

      final Locale languageLocale = new Locale(locale.languageCode, "");
      if (supported.contains(locale))
        return locale;
      else if (supported.contains(languageLocale))
        return languageLocale;
      else {
        final Locale fallbackLocale = fallback ?? supported.first;
        return fallbackLocale;
      }
    };
  }

Obviously this is not an ideal situation. I can't keep the plugin disabled.

IntelliJ 2019.1

There's a new kid on the block and this plugin needs to be upgraded to support it. At least I still don't see the plugin in its latest version in JetBrains.

Feature: generate json keys for other languages based on en.arb

Right now, whenever i add a new key into en.arb i have to update my other **.arb files as well.
Can't we automatically add the newly added json key in en.arb into the other **.arb files? On top of that we could also automatically sort the **.arb keys based on the sorting of en.arb.

The key 'other' cannot be used

When using the key other in the .arb file
e.g.

{ 
"other": "Other",
"hello": "Hello"
}

The plugin will generate the following:

String get hello => "Hello";
String (dynamic param) {
    switch (param.toString()) {
      default:
        return "Other";
    }
  }

It generates a plurals function without a function name which will break the generated i18n.dart file.
I don't know if this can be resolved, because plurals use this suffix.

Plugin version:

1.0.1

Android Studio:

Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 16, 2019
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

In the meantime, I'll use otherOther as a key.

On another note

Maybe consider using optional parameters using plurals. This will always result in using the default value.

e.g.

String product({dynamic param}) {
    switch (param.toString()) {
      case "1":
        return "Product";
      default:
        return "Products";
    }
  }

This way you can use S.of(context).product()

In the Usage Readme, delegates are missing?

I was unable to get my app to run until I changed this:
localizationsDelegates: [S.delegate],

to this:
localizationsDelegates: [S.delegate,GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate],

Otherwise I get null errors like
The getter 'openAppDrawerTooltip' was called on null.

Is this okay? And if so, maybe the usage readme should be updated? (Amazing plugin btw)

feature: custom boiler-plate code templates

Hey, great plugin!

It would be helpful though to allow customer boiler plate code templates. In particular I would like to do something like:

class S implements WidgetsLocalizations {

  static S current;

and have the GeneratedLocalizationsDelegate do something like:

  @override
  Future<S> load(Locale locale) {
    final String lang = getLang(locale);
    if (lang != null) {
      switch (lang) {
        case "cs":
          S.current = const $cs();
          return SynchronousFuture<S>(S.current);

so that I can also use the internationalised strings outside of the build context, e.g. in blocs.

Any chance?

how to localize for chinese

i try to define
string_zh.arb => Traditional Chinese for Taiwan
string_zh_CN.arb => Simplify Chinese
string_zh_HK.arb => Traditional Chinese for Hong Kong

but, always use string_zh_HK when switching different chinese language.

What is the correct way to handle it?

Intention Description Dir URL is null: Extract the string resource; ExtractStringResourceDart [Plugin: FlutterI18n]

IntelliJ IDEA 2017.3.5 (Community Edition)
Build #IC-173.4674.33, built on March 5, 2018
JRE: 1.8.0_152-release-1024-b15 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

Plugin Version: 0.0.4

I get the following exception everytime I start IntelliJ:

Intention Description Dir URL is null: Extract the string resource; ExtractStringResourceDart [Plugin: FlutterI18n]
com.intellij.diagnostic.PluginException: Intention Description Dir URL is null: Extract the string resource; ExtractStringResourceDart [Plugin: FlutterI18n]
	at com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData.getDirURL(IntentionActionMetaData.java:114)
	at com.intellij.codeInsight.intention.impl.config.BeforeAfterActionMetaData.getDescription(BeforeAfterActionMetaData.java:151)
	at com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings.processMetaData(IntentionManagerSettings.java:160)
	at com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings.registerMetaData(IntentionManagerSettings.java:149)
	at com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings.registerIntentionMetaData(IntentionManagerSettings.java:80)
	at com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl.lambda$registerIntentionFromBean$0(IntentionManagerImpl.java:96)
	at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:246)
	at com.intellij.util.Alarm$Request.runSafely(Alarm.java:417)
	at com.intellij.util.Alarm$Request.access$700(Alarm.java:344)
	at com.intellij.util.Alarm$Request$1.run(Alarm.java:384)
	at com.intellij.util.Alarm$Request.run(Alarm.java:395)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:242)
	at com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:212)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

NoSuchMethodError

When I try to use the plugin I got that error....do I make something wrong or is it the plugin??

I/flutter (30012): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (30012): The following NoSuchMethodError was thrown building MyApp(dirty): I/flutter (30012): The getter '_locale' was called on null. I/flutter (30012): Receiver: null I/flutter (30012): Tried calling: _locale I/flutter (30012): I/flutter (30012): When the exception was thrown, this was the stack: I/flutter (30012): #0 Object.noSuchMethod (dart:core-patch/dart:core/object_patch.dart:46) I/flutter (30012): #1 S.of (package:bill_scanner/generated/i18n.dart:20:25)

class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', localizationsDelegates: [S.delegate], supportedLocales: S.delegate.supportedLocales, localeResolutionCallback: S.delegate.resolution(fallback: new Locale("en", "")), theme: new ThemeData( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or press Run > Flutter Hot Reload in IntelliJ). Notice that the // counter didn't reset back to zero; the application is not restarted. primarySwatch: Colors.blue, ), home: new MyHomePage(title: "test title"), ); } }

floatingActionButton: new FloatingActionButton( onPressed: _incrementCounter, tooltip: S.of(context).title, child: new Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods.

Support newer versions of IntelliJ/Android Studio

Hello,

The plugin is currently supporting a 181.x version of IntelliJ.
The current stable version of IntelliJ is 182.x and some RC for 183.x are even available.

Do you plan to support these new releases?

Thanks for your work!

Plugin stopped generating i18n.dart file

My plugin stopped generating the i18n file, I am guessing some upgrade of the plugin or flutter broke it.
Tried to uninstall and reinstall the plugin and got this exception:

No match found
java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:536)
at java.util.regex.Matcher.group(Matcher.java:496)
at eu.long1.flutter.i18n.workers.I18nFileGenerator$appendPluralMethod$parameterName$1.invoke(I18nFileGenerator.kt:205)
at eu.long1.flutter.i18n.workers.I18nFileGenerator$appendPluralMethod$parameterName$1.invoke(I18nFileGenerator.kt:20)
at eu.long1.flutter.i18n.workers.I18nFileGenerator.appendPluralMethod$i18n(I18nFileGenerator.kt:203)
at eu.long1.flutter.i18n.workers.I18nFileGenerator.appendSClass(I18nFileGenerator.kt:87)
at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:42)
at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:70)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:917)
at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:146)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

I am not using plurals syntax in my arb file.

plugins didn't work properly with existing project

I am working on a project, I works fine, until I need to change my device, installed IntelliJ/Android Studio from Jetbrains-Toolbox, installed Flutter, Dart and i18n plugins and run the current project. And then this error appear, and the autogenerated files no longer auto generated.

kotlin.KotlinNullPointerException
	at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:20)
	at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:54)
	at eu.long1.flutter.i18n.actions.RebuildI18nFile$actionPerformed$1.run(RebuildI18nFile.kt:13)
	at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:363)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:124)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:264)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1057)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:263)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:321)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:188)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:323)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:262)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:244)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:126)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:363)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:355)
	at eu.long1.flutter.i18n.actions.RebuildI18nFile.actionPerformed(RebuildI18nFile.kt:13)
	at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:258)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:275)
	at com.intellij.openapi.actionSystem.impl.ActionButton.actionPerformed(ActionButton.java:184)
	at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:148)
	at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:410)
	at java.awt.Component.processEvent(Component.java:6313)
	at java.awt.Container.processEvent(Container.java:2237)
	at java.awt.Component.dispatchEventImpl(Component.java:4903)
	at java.awt.Container.dispatchEventImpl(Container.java:2295)
	at java.awt.Component.dispatchEvent(Component.java:4725)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
	at java.awt.Container.dispatchEventImpl(Container.java:2281)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4725)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:737)
	at java.awt.EventQueue$4.run(EventQueue.java:735)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:719)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:664)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:363)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

it works fine when I create a new project.

Is there a plugin config option?

Great plugin, and thanks for sharing it!

But I do think that generating a class named S can be a bit confusing when reading through the code after a few weeks/months.

Is there a way to override/set/change the name of the auto-generated class?

For example, I would change the config of the plugin to generate a class called Strings and use it as Strings.of(context).myStringKey or maybe IntlStrings. That way when I (or someone else going through the codebase) can avoid asking themselves what S is.

Note: I have created a wrapper around S:

class Strings extends S {
  static Strings of(BuildContext context) => S.of(context);
}

Works fine when running the app with context and all.
But am now hitting problems when running unit tests. They're failing with:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞══════════════════
The following assertion was thrown building BlocBuilder<IssueEvent, IssueState>(dirty, dependencies:
[_LocalizationsScope-[GlobalKey#176cc]], state: _BlocBuilderBaseState<IssueEvent,
IssueState>#4fc5b):
type '$en' is not a subtype of type 'Strings'
...

Because $en is a subclass of S in the auto-generated file just as Strings is, and now Strings and $en are siblings.

Cheers.

Type 'en' is not a subtype of type 'S'

I use flutter sdk 0.9.4 and the default config as in your plugin document:

Widget build(BuildContext context) {
    return new MaterialApp(
      onGenerateTitle: (BuildContext context) => S.of(context).app_title,
      localizationsDelegates: [S.delegate,],
      supportedLocales: S.delegate.supportedLocales,
      localeResolutionCallback:
          S.delegate.resolution(fallback: new Locale("en", "")),
      theme: new ThemeData(
                primarySwatch: Colors.blue,
      ),
      home: new HomeView(),
    );
}

And in HomeView, I use like that:
new Text(S.of(context).start),

Then it makes error like below:

22:33:27.416 2 info flutter.tools I/flutter (11541): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
22:33:27.416 3 info flutter.tools I/flutter (11541): The following assertion was thrown building HomeView(dirty):
22:33:27.416 4 info flutter.tools I/flutter (11541): type 'en' is not a subtype of type 'S'
22:33:27.416 5 info flutter.tools I/flutter (11541): 
22:33:27.416 6 info flutter.tools I/flutter (11541): Either the assertion indicates an error in the framework itself, or we should provide substantially
22:33:27.416 7 info flutter.tools I/flutter (11541): more information in this error message to help you determine and fix the underlying cause.
22:33:27.416 8 info flutter.tools I/flutter (11541): In either case, please report this assertion by filing a bug on GitHub:
22:33:27.416 9 info flutter.tools I/flutter (11541):   https://github.com/flutter/flutter/issues/new
22:33:27.416 10 info flutter.tools I/flutter (11541): 
22:33:27.416 11 info flutter.tools I/flutter (11541): When the exception was thrown, this was the stack:
22:33:27.432 12 info flutter.tools I/flutter (11541): #0      _LocalizationsState.resourcesFor (package:flutter/src/widgets/localizations.dart:533:13)
22:33:27.432 13 info flutter.tools I/flutter (11541): #1      Localizations.of (package:flutter/src/widgets/localizations.dart:445:39)
22:33:27.447 14 info flutter.tools I/flutter (11541): #2      S.of (package:eye_test_game/generated/i18n.dart:19:21)
22:33:27.447 15 info flutter.tools I/flutter (11541): #3      HomeView.build (package:eye_test_game/presentations/home/home_view.dart:23:33)
22:33:27.447 16 info flutter.tools I/flutter (11541): #4      StatelessElement.build (package:flutter/src/widgets/framework.dart:3731:28)
22:33:27.447 17 info flutter.tools I/flutter (11541): #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3678:15)
22:33:27.447 18 info flutter.tools I/flutter (11541): #6      Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 19 info flutter.tools I/flutter (11541): #7      StatelessElement.update (package:flutter/src/widgets/framework.dart:3738:5)
22:33:27.447 20 info flutter.tools I/flutter (11541): #8      Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 21 info flutter.tools I/flutter (11541): #9      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 22 info flutter.tools I/flutter (11541): #10     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 23 info flutter.tools I/flutter (11541): #11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.447 24 info flutter.tools I/flutter (11541): #12     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 25 info flutter.tools I/flutter (11541): #13     StatelessElement.update (package:flutter/src/widgets/framework.dart:3738:5)
22:33:27.447 26 info flutter.tools I/flutter (11541): #14     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 27 info flutter.tools I/flutter (11541): #15     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 28 info flutter.tools I/flutter (11541): #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 29 info flutter.tools I/flutter (11541): #17     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 30 info flutter.tools I/flutter (11541): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 31 info flutter.tools I/flutter (11541): #19     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 32 info flutter.tools I/flutter (11541): #20     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 33 info flutter.tools I/flutter (11541): #21     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 34 info flutter.tools I/flutter (11541): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 35 info flutter.tools I/flutter (11541): #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.447 36 info flutter.tools I/flutter (11541): #24     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 37 info flutter.tools I/flutter (11541): #25     StatefulElement.update (package:flutter/src/widgets/framework.dart:3835:5)
22:33:27.447 38 info flutter.tools I/flutter (11541): #26     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 39 info flutter.tools I/flutter (11541): #27     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.447 40 info flutter.tools I/flutter (11541): #28     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 41 info flutter.tools I/flutter (11541): #29     StatelessElement.update (package:flutter/src/widgets/framework.dart:3738:5)
22:33:27.447 42 info flutter.tools I/flutter (11541): #30     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 43 info flutter.tools I/flutter (11541): #31     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.447 44 info flutter.tools I/flutter (11541): #32     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 45 info flutter.tools I/flutter (11541): #33     StatefulElement.update (package:flutter/src/widgets/framework.dart:3835:5)
22:33:27.447 46 info flutter.tools I/flutter (11541): #34     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 47 info flutter.tools I/flutter (11541): #35     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 48 info flutter.tools I/flutter (11541): #36     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 49 info flutter.tools I/flutter (11541): #37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.447 50 info flutter.tools I/flutter (11541): #38     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 51 info flutter.tools I/flutter (11541): #39     ProxyElement.update (package:flutter/src/widgets/framework.dart:3947:5)
22:33:27.447 52 info flutter.tools I/flutter (11541): #40     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 53 info flutter.tools I/flutter (11541): #41     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.447 54 info flutter.tools I/flutter (11541): #42     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.447 55 info flutter.tools I/flutter (11541): #43     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.447 56 info flutter.tools I/flutter (11541): #44     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.447 57 info flutter.tools I/flutter (11541): #45     StatefulElement.update (package:flutter/src/widgets/framework.dart:3835:5)
22:33:27.447 58 info flutter.tools I/flutter (11541): #46     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.463 59 info flutter.tools I/flutter (11541): #47     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.463 60 info flutter.tools I/flutter (11541): #48     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.463 61 info flutter.tools I/flutter (11541): #49     StatelessElement.update (package:flutter/src/widgets/framework.dart:3738:5)
22:33:27.463 62 info flutter.tools I/flutter (11541): #50     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.463 63 info flutter.tools I/flutter (11541): #51     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4803:14)
22:33:27.463 64 info flutter.tools I/flutter (11541): #52     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.463 65 info flutter.tools I/flutter (11541): #53     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.463 66 info flutter.tools I/flutter (11541): #54     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.463 67 info flutter.tools I/flutter (11541): #55     ProxyElement.update (package:flutter/src/widgets/framework.dart:3947:5)
22:33:27.463 68 info flutter.tools I/flutter (11541): #56     Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15)
22:33:27.463 69 info flutter.tools I/flutter (11541): #57     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16)
22:33:27.463 70 info flutter.tools I/flutter (11541): #58     Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5)
22:33:27.463 71 info flutter.tools I/flutter (11541): #59     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2273:33)
22:33:27.463 72 info flutter.tools I/flutter (11541): #60     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:673:20)
22:33:27.463 73 info flutter.tools I/flutter (11541): #61     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
22:33:27.463 74 info flutter.tools I/flutter (11541): #62     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
22:33:27.463 75 info flutter.tools I/flutter (11541): #63     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
22:33:27.463 76 info flutter.tools I/flutter (11541): #64     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
22:33:27.463 77 info flutter.tools I/flutter (11541): #66     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
22:33:27.463 78 info flutter.tools I/flutter (11541): #67     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
22:33:27.463 79 info flutter.tools I/flutter (11541): #68     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
22:33:27.463 80 info flutter.tools I/flutter (11541): (elided one frame from package dart:async)
22:33:27.463 81 info flutter.tools I/flutter (11541): ════════════════════════════════════════════════════════════════════════════════════════════════════
22:33:27.525 82 info flutter.tools Reloaded 3 of 431 libraries in 1,049ms.

kotlin.KotlinNullPointerException

IntelliJ IDEA 2018.1.2 (Community Edition)
Build #IC-181.4668.68, built on April 24, 2018
JRE: 1.8.0_152-release-1136-b29 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.4

Plugin Version: 0.0.5

I get the following exception everytime I start IntelliJ:

kotlin.KotlinNullPointerException
io.reactivex.exceptions.OnErrorNotImplementedException: kotlin.KotlinNullPointerException
	at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
	at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
	at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:77)
	at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:67)
	at io.reactivex.internal.operators.observable.ObservableInterval$IntervalObserver.run(ObservableInterval.java:83)
	at io.reactivex.internal.schedulers.ScheduledDirectPeriodicTask.run(ScheduledDirectPeriodicTask.java:38)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: kotlin.KotlinNullPointerException
	at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:176)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:159)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:258)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:245)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$2.accept(Initializer.kt:58)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$2.accept(Initializer.kt:30)
	at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:63)
	... 9 more
Caused by: kotlin.KotlinNullPointerException
	at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:20)
	at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:51)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$2$1.run(Initializer.kt:59)
	at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:256)
	at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:238)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:175)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1010)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:174)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:214)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:137)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:105)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:216)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:172)
	at com.intellij.openapi.command.WriteCommandAction.lambda$execute$0(WriteCommandAction.java:159)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransactionAndWait$2(TransactionGuardImpl.java:165)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:447)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:431)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:415)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:779)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:720)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:395)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Plugin stops generating?

Not updating generated files anymore when changing the arb file. Any way to kick it off manually? Maybe an option under the Tools menu?

Getting error in Plugin.

I 'm getting following error when my application is started. And i18n file is not generated.
kotlin.KotlinNullPointerException
at eu.long1.flutter.i18n.files.FileHelpers.getI18nFile(FileHelpers.kt:20)
at eu.long1.flutter.i18n.workers.I18nFileGenerator.generate(I18nFileGenerator.kt:54)
at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:64)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945)
at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:150)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

java.lang.AssertionError: Already disposed: Project (Disposed) xxxxxxx

java.lang.AssertionError: Already disposed: Project (Disposed) xxxxxxx
	at com.intellij.openapi.components.impl.ComponentManagerImpl.lambda$throwAlreadyDisposed$1(ComponentManagerImpl.java:248)
	at com.intellij.openapi.application.ReadAction.lambda$run$1(ReadAction.java:53)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:955)
	at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:57)
	at com.intellij.openapi.application.ReadAction.run(ReadAction.java:53)
	at com.intellij.openapi.components.impl.ComponentManagerImpl.throwAlreadyDisposed(ComponentManagerImpl.java:246)
	at com.intellij.openapi.components.impl.ComponentManagerImpl.getPicoContainer(ComponentManagerImpl.java:239)
	at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:149)
	at com.intellij.psi.PsiManager.getInstance(PsiManager.java:39)
	at eu.long1.flutter.i18n.workers.I18nFileGenerator.<init>(I18nFileGenerator.kt:22)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1$lambda$1.compute(actions.kt:70)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945)
	at eu.long1.flutter.i18n.workers.Initializer$runActivity$$inlined$scheduleAtFixedRate$1.run(Timer.kt:146)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)

Doesn't support zh_TW

The locale comes into GeneratedLocalizationsDelegate_resolve method is 'zh_Hant_TW' on an Android phone that was set to Chinese (Taiwan). The arb file is strings_zh_TW.arb which is Traditional Chinese. We also have strings_zh.arb which is Simplified Chinese.

    final Locale languageLocale = Locale(locale.languageCode, "");
    if (supported.contains(locale)) { // this line return false because the supported locales doesn't include zh_Hant_TW
      return locale;
    } else if (supported.contains(languageLocale)) { // this line returns true because zh is there so we ended up with zh (Simplified Chinese). 
      return languageLocale;
    } else {
      final Locale fallbackLocale = fallback ?? supported.first;
      return fallbackLocale;
    }

It looks like we should have one more if statement to check for language and country locale.

For Chinese, there are also zh_Hant_HW and zh_Hant_MO in addition to zh_Hant_TW. So we need a way to support the scriptCode (Hans or Hant for Simplified Chinese and Traditional Chinese respectively) so that we don't need an arb for each of them. Two arbs for Hant and Hans would be good enough.

How can I add text after a parameter?

I am looking to add a string like "Weight: 20Kg" where 20 should be parameterised and followed by "Kg" without a separating space, however writing something like "Weight: $weightKg" ends up with a variable called weightKg and "Weight: ${weight}Kg" results in a function with bas syntax (missing argument name). Is there a way to overcome this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.