当前位置:网站首页>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.yamlfile - 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: falseAnalysis:
- 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 generateproperty
flutter:uses-material-design: true# Add this property generate: true4. 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!
边栏推荐
猜你喜欢
随机推荐
NC | 土壤微生物组的结构和功能揭示全球湿地N2O释放
MySQL安装(详细,适合小白)
软考 ----- UML设计与分析(下)
Go----Go 语言快速体验之开发环境搭建及第一个项目HelloWord
7月29-31 | APACHECON ASIA 2022
磁盘分区的知识
简单有效又有用的关闭antimalware service executable的方法·备份记录
golang刷leetcode 经典(10) tire树与ac自动机
让你的应用完美适配平板
Nature Microbiology综述:聚焦藻际--浮游植物和细菌互作的生态界面
斯堪尼亚SCANIA OTL标签介绍
Redis 5 种数据结构及对应使用场景
扫码预约 | 观看Apache Linkis数据处理实践以及计算治理能力
深度学习-学习笔记(持续更新)
LeetCode - 105. 从前序与中序遍历序列构造二叉树;023.合并K个升序链表
JVM内存和垃圾回收-06.本地方法栈
2022-07-27
E. Add Modulo 10(规律)
一些不错的博主
Office2021 安装MathType









