From 49991ff863443afed83f832a603e6eb8e3527fe2 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Wed, 31 Mar 2021 14:02:18 +0800 Subject: [PATCH] l10n support --- .gitattributes | 1 + l10n.yaml | 4 ++++ lib/constants/app_values.dart | 6 +++--- lib/l10n/app_zh.arb | 10 ++++++++++ lib/main.dart | 6 ++++-- .../goods_deto_page/deto_code_page/deto_code_page.dart | 5 ++--- .../deto_create_page/deto_create_page.dart | 2 +- lib/pages/home/widget/animate_app_bar.dart | 3 ++- lib/pages/life_pay/life_pay_page.dart | 9 ++++++++- lib/pages/life_pay/widget/life_pay_detail_page.dart | 2 +- lib/pages/life_pay/widget/my_house_page.dart | 5 ++++- .../things_page/widget/add_fixed_submit_page.dart | 3 ++- lib/pages/visitor_access_page/visitor_access_page.dart | 2 +- lib/ui/manager/advice/new_advice_page.dart | 2 +- lib/ui/profile/car/car_manage_card.dart | 2 +- lib/ui/profile/car_parking/car_parking_card.dart | 2 +- lib/ui/profile/house/add_house_page.dart | 2 +- lib/ui/profile/house/house_card.dart | 4 ++-- lib/ui/profile/house/pick_my_house_page.dart | 2 +- lib/utils/headers.dart | 1 + pubspec.lock | 2 +- pubspec.yaml | 2 ++ 22 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 .gitattributes create mode 100644 l10n.yaml create mode 100644 lib/l10n/app_zh.arb diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..ca4b4a72 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.arb diff \ No newline at end of file diff --git a/l10n.yaml b/l10n.yaml new file mode 100644 index 00000000..dff1749c --- /dev/null +++ b/l10n.yaml @@ -0,0 +1,4 @@ +arb-dir: lib/l10n +template-arb-file: app_zh.arb +output-localization-file: app_localizations.dart +output-class: S \ No newline at end of file diff --git a/lib/constants/app_values.dart b/lib/constants/app_values.dart index f847d3f5..f9734570 100644 --- a/lib/constants/app_values.dart +++ b/lib/constants/app_values.dart @@ -1,3 +1,3 @@ -class AppValues { - static const String plotName = '人才公寓智慧小区'; -} +// class AppValues { +// static const String plotName = '人才公寓智慧小区'; +// } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb new file mode 100644 index 00000000..76a6eb9c --- /dev/null +++ b/lib/l10n/app_zh.arb @@ -0,0 +1,10 @@ +{ + "appName": "智慧社区", + "@appName":{ + "description": "应用名称" + }, + "tempPlotName": "人才公寓智慧小区", + "@tempPlotName":{ + "description": "临时使用的小区名称" + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index eae19676..910f65aa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ import 'package:akuCommunity/provider/cart.dart'; import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/developer_util.dart'; +import 'package:akuCommunity/utils/headers.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -87,17 +88,18 @@ class _MyAppState extends State { designSize: Size(750, 1334), allowFontScaling: true, builder: () => GetMaterialApp( - title: '智慧社区', + onGenerateTitle: (context) => S.of(context).appName, debugShowCheckedModeBanner: false, theme: AppTheme.theme, home: SplashPage(), //国际化支持 localizationsDelegates: [ + S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: [const Locale('zh', 'CH')], + supportedLocales: [const Locale('zh')], locale: Locale('zh'), builder: BotToastInit(), navigatorObservers: [BotToastNavigatorObserver()], diff --git a/lib/pages/goods_deto_page/deto_code_page/deto_code_page.dart b/lib/pages/goods_deto_page/deto_code_page/deto_code_page.dart index b3e05dc9..027fbd87 100644 --- a/lib/pages/goods_deto_page/deto_code_page/deto_code_page.dart +++ b/lib/pages/goods_deto_page/deto_code_page/deto_code_page.dart @@ -1,13 +1,12 @@ -import 'package:akuCommunity/constants/app_values.dart'; import 'package:akuCommunity/provider/app_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; +import 'package:get/get.dart'; import 'package:provider/provider.dart'; import 'package:qr_flutter/qr_flutter.dart'; -import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/model/manager/article_QR_code_model.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; @@ -25,7 +24,7 @@ class DetoCodePage extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - AppValues.plotName, + S.of(Get.context).tempPlotName, style: TextStyle(fontSize: 40.sp, color: Color(0xffffffff)), ), SizedBox(height: 10.w), diff --git a/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart b/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart index a0403b3f..0a5885bb 100644 --- a/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart +++ b/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart @@ -109,7 +109,7 @@ class _DetoCreatePageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - AppValues.plotName, + S.of(context).tempPlotName, style: TextStyle( fontWeight: FontWeight.w600, fontSize: 32.sp, diff --git a/lib/pages/home/widget/animate_app_bar.dart b/lib/pages/home/widget/animate_app_bar.dart index 35f91fbf..52178048 100644 --- a/lib/pages/home/widget/animate_app_bar.dart +++ b/lib/pages/home/widget/animate_app_bar.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/constants/app_values.dart'; +import 'package:akuCommunity/utils/headers.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -40,7 +41,7 @@ class _AnimateAppBarState extends State { Widget build(BuildContext context) { final appProvider = Provider.of(context); return AppBar( - title: Text(AppValues.plotName), + title: Text( S.of(context).tempPlotName), backgroundColor: _bgColor, leading: Container( margin: EdgeInsets.only(left: 32.w), diff --git a/lib/pages/life_pay/life_pay_page.dart b/lib/pages/life_pay/life_pay_page.dart index 6d85a58a..1653faf4 100644 --- a/lib/pages/life_pay/life_pay_page.dart +++ b/lib/pages/life_pay/life_pay_page.dart @@ -82,7 +82,14 @@ class _LifePayPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - AppValues.plotName.text.black.size(32.sp).bold.make(), + S + .of(context) + .tempPlotName + .text + .black + .size(32.sp) + .bold + .make(), 10.w.heightBox, appProvider.selectedHouse.roomName.text.black .size(32.sp) diff --git a/lib/pages/life_pay/widget/life_pay_detail_page.dart b/lib/pages/life_pay/widget/life_pay_detail_page.dart index 790dd69f..c60bc2fa 100644 --- a/lib/pages/life_pay/widget/life_pay_detail_page.dart +++ b/lib/pages/life_pay/widget/life_pay_detail_page.dart @@ -94,7 +94,7 @@ class _LifePayDetailPageState extends State { children: [ model.name.text.black.size(30.sp).bold.make(), Spacer(), - '${AppValues.plotName} ${userProvider.currentHouse}' + '${S.of(context).tempPlotName} ${userProvider.currentHouse}' .text .color(ktextSubColor) .size(24.sp) diff --git a/lib/pages/life_pay/widget/my_house_page.dart b/lib/pages/life_pay/widget/my_house_page.dart index 760dc20f..4d30a41c 100644 --- a/lib/pages/life_pay/widget/my_house_page.dart +++ b/lib/pages/life_pay/widget/my_house_page.dart @@ -87,7 +87,10 @@ class _MyHousePageState extends State { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - AppValues.plotName.text + S + .of(context) + .tempPlotName + .text .size(24.sp) .color(ktextSubColor) .bold diff --git a/lib/pages/things_page/widget/add_fixed_submit_page.dart b/lib/pages/things_page/widget/add_fixed_submit_page.dart index 91e66f16..a015f98a 100644 --- a/lib/pages/things_page/widget/add_fixed_submit_page.dart +++ b/lib/pages/things_page/widget/add_fixed_submit_page.dart @@ -4,6 +4,7 @@ import 'package:akuCommunity/constants/app_values.dart'; import 'package:akuCommunity/provider/app_provider.dart'; import 'package:akuCommunity/ui/profile/house/house_owners_page.dart'; import 'package:akuCommunity/ui/profile/house/pick_my_house_page.dart'; +import 'package:akuCommunity/utils/headers.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -221,7 +222,7 @@ class _AddFixedSubmitPageState extends State { body: ListView( children: [ _buildHouseCard( - AppValues.plotName, + S.of(context).tempPlotName, appProvider.selectedHouse.roomName, ), _getType(), diff --git a/lib/pages/visitor_access_page/visitor_access_page.dart b/lib/pages/visitor_access_page/visitor_access_page.dart index 5f423d40..8b7d3bbd 100644 --- a/lib/pages/visitor_access_page/visitor_access_page.dart +++ b/lib/pages/visitor_access_page/visitor_access_page.dart @@ -306,7 +306,7 @@ class _VisitorAccessPageState extends State { child: Column( children: [ _buildHouseCard( - AppValues.plotName, + S.of(context).tempPlotName, appProvider.selectedHouse.roomName, ), _input('访客姓名', '请输入访客姓名', _userName), diff --git a/lib/ui/manager/advice/new_advice_page.dart b/lib/ui/manager/advice/new_advice_page.dart index 751fc1aa..f66d2038 100644 --- a/lib/ui/manager/advice/new_advice_page.dart +++ b/lib/ui/manager/advice/new_advice_page.dart @@ -145,7 +145,7 @@ class _NewAdvicePageState extends State { width: 60.w, ), 40.wb, - '${AppValues.plotName}\n${appProvider.selectedHouse.roomName}' + '${S.of(context).tempPlotName}\n${appProvider.selectedHouse.roomName}' .text .size(32.sp) .black diff --git a/lib/ui/profile/car/car_manage_card.dart b/lib/ui/profile/car/car_manage_card.dart index 123b6201..efb993c3 100644 --- a/lib/ui/profile/car/car_manage_card.dart +++ b/lib/ui/profile/car/car_manage_card.dart @@ -36,7 +36,7 @@ class CarManageCard extends StatelessWidget { ), ), Text( - AppValues.plotName, + S.of(context).tempPlotName, style: Theme.of(context) .textTheme .subtitle2 diff --git a/lib/ui/profile/car_parking/car_parking_card.dart b/lib/ui/profile/car_parking/car_parking_card.dart index 6dbecb69..e3b392ba 100644 --- a/lib/ui/profile/car_parking/car_parking_card.dart +++ b/lib/ui/profile/car_parking/car_parking_card.dart @@ -36,7 +36,7 @@ class CarparkingCard extends StatelessWidget { ), ), Text( - AppValues.plotName, + S.of(context).tempPlotName, style: Theme.of(context) .textTheme .subtitle2 diff --git a/lib/ui/profile/house/add_house_page.dart b/lib/ui/profile/house/add_house_page.dart index 9401c16f..5aa294db 100644 --- a/lib/ui/profile/house/add_house_page.dart +++ b/lib/ui/profile/house/add_house_page.dart @@ -171,7 +171,7 @@ class _AddHousePageState extends State { _renderTile( title: '小区名称', item: _renderPicker( - text: AppValues.plotName, + text: S.of(context).tempPlotName, hintText: '请选择小区', // 跳转到选择小区页面 // TODO 小区页面 diff --git a/lib/ui/profile/house/house_card.dart b/lib/ui/profile/house/house_card.dart index c9e29d15..107b866c 100644 --- a/lib/ui/profile/house/house_card.dart +++ b/lib/ui/profile/house/house_card.dart @@ -109,7 +109,7 @@ class HouseCard extends StatelessWidget { ), ), onPressed: () { - Get.to(()=>PickMyHousePage()); + Get.to(() => PickMyHousePage()); }, shape: RoundedRectangleBorder( borderRadius: @@ -119,7 +119,7 @@ class HouseCard extends StatelessWidget { ), 12.hb, Text( - AppValues.plotName, + S.of(context).tempPlotName, style: Theme.of(context).textTheme.headline3, ), 10.hb, diff --git a/lib/ui/profile/house/pick_my_house_page.dart b/lib/ui/profile/house/pick_my_house_page.dart index 11ea4e16..994aa6ba 100644 --- a/lib/ui/profile/house/pick_my_house_page.dart +++ b/lib/ui/profile/house/pick_my_house_page.dart @@ -196,7 +196,7 @@ class _HouseCard extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ Text( - AppValues.plotName, + S.of(context).tempPlotName, style: Theme.of(context).textTheme.subtitle1.copyWith( color: highlight ? Color(0xFFFF8200) : Color(0xFF333333), diff --git a/lib/utils/headers.dart b/lib/utils/headers.dart index 5ccd4463..c0016417 100644 --- a/lib/utils/headers.dart +++ b/lib/utils/headers.dart @@ -3,3 +3,4 @@ export 'package:akuCommunity/extensions/num_ext.dart'; export 'package:akuCommunity/extensions/widget_list_ext.dart'; export 'package:velocity_x/velocity_x.dart'; export 'package:akuCommunity/const/resource.dart'; +export 'package:flutter_gen/gen_l10n/app_localizations.dart'; diff --git a/pubspec.lock b/pubspec.lock index 9ab4aaf2..754feb35 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -416,7 +416,7 @@ packages: source: hosted version: "4.4.2" intl: - dependency: transitive + dependency: "direct main" description: name: intl url: "https://pub.flutter-io.cn" diff --git a/pubspec.yaml b/pubspec.yaml index 81a1dfa3..61b47be1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter + intl: ^0.17.0 permission_handler: ^6.1.1 package_info: ^2.0.0 provider: ^5.0.0 @@ -75,6 +76,7 @@ dev_dependencies: flutter: uses-material-design: true + generate: true assets: - assets/