Skip to content

Commit

Permalink
[WIP] Add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Jul 29, 2024
1 parent c2f6e25 commit e9ede30
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 262 deletions.
16 changes: 16 additions & 0 deletions Wox.UI.Flutter/wox/lib/api/wox_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:core';

import 'package:wox/entity/wox_ai.dart';
import 'package:wox/entity/wox_image.dart';
import 'package:wox/entity/wox_lang.dart';
import 'package:wox/entity/wox_plugin.dart';
import 'package:wox/entity/wox_query.dart';
import 'package:wox/entity/wox_setting.dart';
Expand Down Expand Up @@ -99,6 +101,20 @@ class WoxApi {
});
}

Future<List<WoxLang>> getAllLanguages() async {
return await WoxHttpUtil.instance.postData("/lang/available", {});
}

Future<Map<String, String>> getLangJson(String langCode) async {
var langJsonStr = await WoxHttpUtil.instance.postData("/lang/json", {
"langCode": langCode,
});

//unmarshal json string to map
var jsonMap = json.decode(langJsonStr);
return jsonMap.cast<String, String>();
}

Future<void> onProtocolUrlReceived(String command, Map<String, String> arguments) async {
await WoxHttpUtil.instance.postData("/deeplink", {
"command": command,
Expand Down
20 changes: 20 additions & 0 deletions Wox.UI.Flutter/wox/lib/entity/wox_lang.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class WoxLang {
final String code;
final String name;

WoxLang({required this.code, required this.name});

factory WoxLang.fromJson(Map<String, dynamic> json) {
return WoxLang(
code: json['Code'],
name: json['Name'],
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['Code'] = code;
data['Name'] = name;
return data;
}
}
7 changes: 6 additions & 1 deletion Wox.UI.Flutter/wox/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ Future<void> initialServices(List<String> arguments) async {
await WoxWebsocketMsgUtil.instance.initialize(Uri.parse("ws://localhost:${Env.serverPort}/ws"), onMessageReceived: launcherController.handleWebSocketMessage);
HeartbeatChecker().startChecking();
Get.put(launcherController);
Get.put(WoxSettingController());
var woxSettingController = WoxSettingController();
Get.put(woxSettingController);

//load lang
var langCode = WoxSettingUtil.instance.currentSetting.langCode;
woxSettingController.updateLang(langCode);
}

Future<void> initDeepLink() async {
Expand Down
Loading

0 comments on commit e9ede30

Please sign in to comment.