goodjob_language 1.0.1 goodjob_language: ^1.0.1 copied to clipboard
Goodjob-SDK是为了满足国际化翻译,实现了一键配置翻译结果同步到应用上,使开发者在开发过程中不再需要关注于文案的翻译和撰写,能将更大的精力放在研发上。
账号注册及申请 #
1.登陆 https://goodjob.ai/ 申请成为开发者
2.面板栏选择创建新项目
3.个人中心查看生成的 apiKey 和 apiSecret.
SDK-Flutter集成 #
集成方式 #
dependencies:
goodjob_language: ^latest_version
功能使用 #
- 初始化 sdk
GoodJobBusiness _business = GoodJobBusiness.getInstance();
var res = await _business.initSDK(
apiKey: "goodjob_api_key",
apiSecret: "goodjob_api_secret",
id: '10133',
isDebug: true);
- 获取翻译结果
keyName需要和 goodjob 配置的名称一一对应,如需修改请在后台操作,默认中文
var res = await _business.interpret(keyName);
- 切换语言
_business.switchLanguage(language: lang);
- 获取已添加语言列表
_business.getLanguageList();
其它功能 #
如果想控制全局状态的变更,建议本地手动导入 provider 库
dependencies:
provider: ^4.0.5
文档provider官方文档 https://pub.dev/packages/provider
example以4.0.5为例:
- 定义 Counter 文件
class Counter with ChangeNotifier,DiagnosticableTreeMixin{
String _key10 = "";
String get key10 => _key10;
void initCounter({String lang}) async {
GoodJobBusiness _business = GoodJobBusiness.getInstance();
if (lang != null) {
_business.switchLanguage(language: lang);
}
_key10 = await _business.interpret("key10");
notifyListeners();
}
}
- 修改 main 中 App 入口
void main() {
runApp(MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => Counter()),
],
child: MyApp(),
));
}
- 使用
Text('${Provider.of<Counter>(context).key10}')