当前位置:网站首页>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
- 让你的应用完美适配平板
- NC | 土壤微生物组的结构和功能揭示全球湿地N2O释放
- 项目分析(复杂嵌入式系统设计)
- ALV概念讲解
- 服务器Centos7 静默安装Oracle Database 12.2
- 健康报告-设计与实现
- shell:条件语句
- A Review of Nature Microbiology: Focusing on the Algae--Ecological Interface of Phytoplankton-Bacteria Interactions
猜你喜欢
随机推荐
平稳发展 | 西欧地区手游玩家的数据和洞察
MySQL安装时一直卡在starting server
golang刷leetcode动态规划(11)不同路径
2022-07-28
[安洵杯 2019]easy_web
分享一个 web 应用版本监测 (更新) 的工具库
2022-07-27
MYSQL关键字执行顺序?
ABAP语法小复习
牛客题目——滑动窗口的最大值、矩阵最长递增路径、顺时针旋转矩阵、接雨水问题
golang刷leetcode 动态规划(13) 最长公共子序列
深度学习-学习笔记(持续更新)
7.24 - 每日一题 - 408
golang刷leetcode动态规划(12)最小路径和
Geoserver+mysql+openlayers2
Geoserver+mysql+openlayers
你想要的宏基因组-微生物组知识全在这(2022.8)
Compose主题切换——让你的APP也能一键换肤
golang刷leetcode 经典(11) 朋友圈
es 读流程源码解析