fluintl 0.1.3

README of English

fluintl (Flutter 国际化) #

Pub

fluintl 是一个为应用提供国际化的库,可快速集成实现应用多语言。该库封装了一个国际化支持类,通过提供统一方法getString(id)获取字符串。CustomLocalizations多语言支持类。LBaseState可简洁获取字符串。

关于使用本开源库 #

如果您是用于公司项目,请随意使用~
如果您是用于开源项目,未经本人许可,请勿copy源码到您的项目使用!
使用方式:

dependencies:
  fluintl: ^0.1.3  

v0.1.3(2019.03.25) #

支持复用。
替换字符串格式要求:'%${index}$s' ,{index} 第几个参数,从0开始。

 Ids.click_times: '%\$0\$s点击了%\$1\$s次',   
   
 IntlUtil.getString(context, Ids.click_times, params: ['Tom', '$_counter'])  
 // print: Tom点击了0次

使用步骤: #

1.创建多语言资源字符串id管理类Ids 和 多语言资源Map

///多语言资源id管理类.  
class Ids {  
  static String titleHome = 'title_home'; 
}  
///简单多语言资源.  
Map<String, Map<String, String>> localizedSimpleValues = {  
  'en': {    
    Ids.titleHome: 'Home',  
  },  
  'zh': {    
    Ids.titleHome: '主页',  
  },  
};  
///多语言资源.  
Map<String, Map<String, Map<String, String>>> localizedValues = {  
  'en': {  
    'US': {  
      Ids.titleHome: 'Home',  
    }  
  },  
  'zh': {  
    'CN': {  
      Ids.titleHome: '主页',  
    },  
    'HK': {  
      Ids.titleHome: '主頁',  
    },  
  }  
};  

2.在MyApp initState配置多语言资源(可配置通用或简单多语言资源,二选一)

  void initState() {    
    super.initState();      
//    setLocalizedSimpleValues(localizedSimpleValues);//配置简单多语言资源  
    setLocalizedValues(localizedValues); //配置多语言资源      
  }   

3.在MaterialApp指定localizationsDelegates和supportedLocales:

MaterialApp(  
   home: MyHomePage(),  
   localizationsDelegates: [  
   GlobalMaterialLocalizations.delegate,  
   GlobalWidgetsLocalizations.delegate,  
   CustomLocalizations.delegate //设置本地化代理     
   ],  
   supportedLocales: CustomLocalizations.supportedLocales,//设置支持本地化语言集合     
);  

4.字符串获取

 IntlUtil.getString(context, Ids.titleHome);
 IntlUtil.getString(context, Ids.titleHome, params: [param1, param2]); 
 CustomLocalizations.of(context).getString(Ids.titleHome)

5.其他(不推荐使用)

 //在主页初始化.
 class _MyHomePageState extends State<MyHomePage> {
  Widget build(BuildContext context) {
    CustomLocalizations.init(context);
    ...
  }

 // 字符串获取
 CustomLocalizations.instance.getString(Ids.titleHome)
 extends or with LBaseState()  (MyHomePageState不能使用)
 cl.getString(Ids.titleHome)

6.应用国际化详细使用请参考flutter_wanandroidApp。
Q:Flutter国际化系统切换iOS不生效问题?
A:在Xcode项目Localizations下添加支持语言即可,原文

Add dependency #

dependencies:
  flutter_localizations:
    sdk: flutter  
    
  fluintl: x.x.x  #latest version

APIs #

setLocalizedSimpleValues(values)                    : 配置简单多语言资源.
setLocalizedValues(values)                          : 配置多语言资源.
CustomLocalizations.delegate                        : 自定义本地化代理.
CustomLocalizations.supportedLocales                : 本地支持的语言环境.
CustomLocalizations.of(context)                     : 获取CustomLocalizations.
getString(id, {languageCode, countryCode, params})  : 通过id获取字符串,可指定languageCode,countryCode.
IntlUtil.getString(context, id, params)             : 通过id获取字符串,可指定languageCode,countryCode.

//不推荐使用
CustomLocalizations.init(context)                   : 自定义本地化代理初始化.(在MyHomePage初始化)
LBaseState (extends or with LBaseState)             : 可方便简洁获取字符串
cl.getString(id).(MyHomePage不能使用)

Example #

Demo: flutter_wanandroid.

APK:点击下载 v0.1.x

APK QR: #

flutter_wanandroid

Screenshot #

image

image

关于作者 #

GitHub : Sky24n
简书     : Sky24n
掘金     : Sky24n
Pub      : Sky24n
Email   : 863764940@qq.com
如果您觉得本项目不错的话,来个star支持下作者吧!

0.1.3 #

  • TODO: add multiplexing. 新增复用。like:“你点击了{time}次”。

0.1.2 #

  • TODO: add IntlUtil.

0.1.1 #

  • TODO: readme update.

0.1.0 #

  • TODO: fluintl initial release.

example/README.md

fluintl_example #

Demonstrates how to use the fluintl plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fluintl: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fluintl/fluintl.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Jul 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin