当前位置:网站首页>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!
边栏推荐
猜你喜欢
Office2021 安装MathType
Gradle系列——Gradle的build.gradle文件详情,项目发布(基于Gradle文档7.5)day3-3
实现客户服务自助,打造产品知识库
安装Mac版Mysql卡在Installation阶段,彻底清理mysql并重装mysql
【C语言刷题】Leetcode238——除自身以外数组的乘积
Golang swagger :missing required param comment parameters
MySQL安装时一直卡在starting server
NC | 土壤微生物组的结构和功能揭示全球湿地N2O释放
es 读流程源码解析
NC | Structure and function of soil microbiome reveal N2O release from global wetlands
随机推荐
B站HR对面试者声称其核心用户都是生活中的Loser
2022-07-27
松鼠短视频系统为用户加入随机头像代码-快速为用户加上随机头衔
实现客户服务自助,打造产品知识库
Geoserver+mysql+openlayers
shell:条件语句
E. Add Modulo 10(规律)
【Psychology · Characters】Issue 1
ShardingSphere-proxy +PostgreSQL实现读写分离(静态策略)
治疗 | 如何识别和处理消极想法
服务器Centos7 静默安装Oracle Database 12.2
leetcode刷题记录:7.整数反转,8.字符串转整数,9.回文数
如何获取EasyCVR平台设备通道的RTMP视频流地址?
分享一个 web 应用版本监测 (更新) 的工具库
AI科学家:自动发现物理系统的隐藏状态变量
【软件工程导论】软件工程导论笔记
MySQL安装配置教程(超级详细、保姆级)
解析Collection接口中的常用的被实现子类重写的方法
What is a Field Service Management System (FSM)?what is the benefit?
idea 配置resin