当前位置:网站首页>Flutter with internationalized adapter automatically generated
Flutter with internationalized adapter automatically generated
2022-08-02 22:34:00 【Front-end code farmer Xiaowang】

1. Introduction
During the study of other people's projects, I suddenly discovered this solution and shared it specially. It turns out that flutter already has a set of mature internationalization generation functions. After the configuration is completed, you only need to write arb
.The main steps are as follows
- 1. Create a new
l10n.yaml
file - 2. Add and configure the required files
- 3. Change pubspec.yaml
- 4.flutter packages get
- 5. Use
1. Create a new l10n.yaml
file
Add the following:
arb-dir: lib/l10n/arbtemplate-arb-file: app_en.arboutput-localization-file: app_localizations.dartnullable-getter: false
Analysis:
- arb-dir: directory where arb is located
- template-arb-file: the default arb file
- output-localization-file: export filename
- nullable-getter: get if the internationalized text is nullable
2. Add and configure required files
Create new files and folders as follows:
- lib* arb* app_en.arb* app_es.arb* l10n.dart under the project

Content of the app_en.arb file
{"@@locale": "en","appName": "Remarks","@appName": {"description": "Remarks"}}
@appName
means to configure something, description
means to add comments, app_es.arb can be obtained in the same way
l10n.dart The code is as follows: (Although there is an error in the imported content, don't worry about it)
import 'package:flutter/widgets.dart';import 'package:flutter_gen/gen_l10n/app_localizations.dart';export 'package:flutter_gen/gen_l10n/app_localizations.dart';extension AppLocalizationsX on BuildContext {AppLocalizations get l10n => AppLocalizations.of(this);}
3. Change pubspec.yaml
Add generate
property
flutter:uses-material-design: true# Add this property generate: true
4. Run flutter packages get
After the operation is successful, you can generate the code for internationalization adaptation in the .dart_tool
directory, and then re-check the code that reported the error before, it is normal

5. Use
MaterialApp is modified as follows:

Where to use:

There are many more contents of arb, such as adding parameters, etc., you can study it yourself, the above is over!
边栏推荐
猜你喜欢
随机推荐
Brain-computer interface 003 | Musk said that he has realized a virtual self-dialogue with the cloud, and related concept shares have risen sharply
【LeetCode】1374. 生成每种字符都是奇数个的字符串
shell:条件语句
一些不错的博主
7.23 - 每日一题 - 408
spack install报错/tmp/ccBDQNaB.s: Assembler message:
竞赛:糖尿病遗传风险检测挑战赛(科大讯飞)
「面试必会」这应该是最有深度的TCP三次握手、四次挥手细节讲解
当TIME_WAIT状态的TCP正常挥手,收到SYN后…
【OpenNI2】资料整理 -- 不断更新中
清除浮动与BFC
J9数字论:互联网跨链桥有什么作用呢?
MySQL 事件调度
一款好用的FAQ搭建工具
JVM内存和垃圾回收-05.虚拟机栈
MaxCompute 的SQL 引擎参数化视图具体有哪些增强功能?
动态生成不同类型的订单,请问如何存放到Mongodb数据库?
Therapy | How to Identify and Deal with Negative Thoughts
让你的应用完美适配平板
十六进制文本的字节序问题