English 中文(简体)
为什么不产生国际化档案?
原标题:Why is Flutter not generating the internationalization files?
最佳回答

奥基做了一些更多的挖掘工作,我已经解决了这个问题。 基本上,“彩虹”文件略微过时。

首先,所生成的档案正在生成之中,但在>code><project_dir>dart_tools/flutter_gen/genl10n上重新编号。 发电机制作合成材料,自动提供给该项目,因此无需再添加<条码>。 变化。

第二,<代码>main.dart 必须考虑这一点:

import  package:flutter/material.dart ;
import  package:flutter_gen/gen_l10n/app_localizations.dart ;

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      supportedLocales: AppLocalizations.supportedLocales,
      title:  My app ,
      home: ... ,
    );
  }
}

Two things here:

  1. The importing of the app_localizations.dart generated file (which the docs do mention but perhaps not explain well) and ...
  2. Changing the localizationsDelegates and supportedLocales. You don t need to list all the delegates and locales mentioned in the docs as the generated localisation files automatically include them. Just switch to the two properties of AppLocalizations.

PS

在撰写上述著作后,我试图将上述标题国际化:

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      supportedLocales: AppLocalizations.supportedLocales,
      title: AppLocalizations.of(context).applicationTitle,
      home: ... ,
    );
  }

专题失败——原因是,在决定标题时,尚未确定代表和地方代表,因此从<代码>App Localizations.of(context)null. 相反,你们需要改写如下:

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      supportedLocales: AppLocalizations.supportedLocales,
      onGenerateTitle: (context) => AppLocalizations.of(context).applicationTitle,
      home: ... ,
    );
  }
```.  

`onGeneratedTitle` is called after the widget is setup which means localisation is available.
问题回答

Addition to @drekka answer,

你们需要管理

flutter gen-l10n

如果不自动产生。

在需要时遇到类似问题,即通过国家扫盲委员会(CLI)在根本上(CLI)创建这些档案。

首先,应当有<代码>intl_utils作为项目依赖或在全球启动。

To install it as a dependency (and manage its version per project) - just add intl_utils: ^2.1.0 to the dependencies section of your pubspec.yaml (don t forget to set the version you need). After that, from the project directory run:

flutter gen-l10n --template-arb-file=intl_en.arb
flutter pub run intl_utils:generate

(change intl_en.arb to You actual .arb 如与缺省代码相匹配,则文档名称或表示整个参数。

To activate intl_utils globally (and use a single version of intl_utils on all your projects), do the following:

dart pub global activate intl_utils 2.1.0

然后从项目目录中管理:

flutter gen-l10n --template-arb-file=intl_en.arb
dart pub global run intl_utils:generate

就我而言,由于该项目的吨位尚未移至使用无效的安全性,加上<条码>intl_utils<>code>,由于项目依赖导致安全问题无效,因此在全球使用<条码>intl_utils 1.9.0。

Run this on your terminal or command-line:
dart pub global activate intl_utils 2.1.0
OR
dart pub global run intl_utils:generate

问题相同。 意外发现,我在<条码>lib上建立了10n.yaml,而不是基地 d。 Moved it should be, and all work!

如果在共和国内添加这一法典。 日元自动产生

flutter_intl:
  enabled: true
  class_name: AppLocalizations

http://www.ohchr.org。

经过一些研究,VsCode(就我的情况而言)似乎不见最近生成的<编码>申请-地点化.dart文档的更新。

www.un.org/Depts/DGACM/index_spanish.htm 为了解决这一问题,仅打开了这里的生成文件:。

.dart_tool/flutter_gen/gen_l10n/app_ localizations.dart

You should see your app_localizations.dart file updated

作为催复,在编辑<代码>.arb后,您需要发射flutter pub,以便作最新改动。

If you have the intl plugin in your code editor (Android Studio) then you should have this generated folder (lib/generated/l10n.dart).

在您的终端站内指挥这一指挥

flutter pub run intl_utils:generate

之后将开展工作。

At home, there was a connection problem, I have tools > Flutter > flutter upgrade

我也存在同样的问题,因为我从另一个开发商进口了该项目,没有一个解决办法帮助我。 在增加依赖性之后,你必须删除一切,并一劳永逸地启动该方案。 之后,该档案即立案。 只有到那时,你才能将档案输入该类别,并与之合作。

I had the same problem , I was using vs code, just restart vs code and everything will work just fine.

ERROR: Failed to generate localization files. type Null is not a subtype of type int of index pub finished with exit code 2

页: 1





相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签