Skip to content

Commit

Permalink
💾 Feat: Now you can change language!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynesshely committed Mar 13, 2023
1 parent 10a7124 commit 36f3ed7
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 19 deletions.
8 changes: 7 additions & 1 deletion KitX Website Flutter/kitx_website/lib/main.dart
@@ -1,12 +1,15 @@
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:get/get.dart';

import 'package:kitx_website/pages/home_page.dart';

import 'package:kitx_website/themes/light_theme.dart';
import 'package:kitx_website/themes/dark_theme.dart';

import 'package:kitx_website/utils/global.dart';
import 'package:kitx_website/utils/translations.dart';

Future<void> main() async {
await Global.init();
Expand All @@ -27,6 +30,9 @@ class MainApp extends StatelessWidget {
theme: lightThemeData,
darkTheme: darkThemeData,
debugShowCheckedModeBanner: false,
translations: Translation(),
locale: ui.window.locale,
fallbackLocale: Locale('en', 'US'),
home: const HomePage(),
),
);
Expand Down
Expand Up @@ -118,19 +118,28 @@ Widget getDownloadList(BuildContext context) {
children: [
StandardPlatformItem(
title: 'Windows',
subTitle: 'Windows 10/11 supported',
subTitle: 'Download_Supported'.tr.replaceAll(
'%content%',
'Windows 10/11',
),
leading: const Icon(CommunityMaterialIcons.microsoft_windows),
onTap: () => showItemsDialog(
context,
[
StandardDownloadItem(
title: '适用于 Windows 64 位 (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Windows ${'Bits_64'.tr} (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'win-x64-single.pubxml',
onTap: () => beginDownload(context, 'win-x64-single.pubxml'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 Windows 32 位 (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Windows ${'Bits_32'.tr} (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'win-x86-single.pubxml',
onTap: () => beginDownload(context, 'win-x86-single.pubxml'),
),
Expand All @@ -140,25 +149,37 @@ Widget getDownloadList(BuildContext context) {
SizedBox(height: tilesPadding),
StandardPlatformItem(
title: 'GNU/Linux',
subTitle: 'Tested on Ubuntu 20.04+, Deepin ...',
subTitle: 'Download_Tested'.tr.replaceAll(
'%content%',
'Ubuntu 20.04+, Deepin ...',
),
leading: const Icon(CommunityMaterialIcons.linux),
onTap: () => showItemsDialog(
context,
[
StandardDownloadItem(
title: '适用于 Linux 64 位 (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Linux ${'Bits_64'.tr} (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'linux-x64-single.pubxml',
onTap: () => beginDownload(context, 'linux-x64-single.pubxml'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 Linux arm 架构处理器 (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Linux ${'CPU_ARM'.tr} (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'linux-arm-single.pubxml',
onTap: () => beginDownload(context, 'linux-arm-single.pubxml'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 Linux arm 架构 64 位处理器 (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Linux ${'CPU_ARM64'.tr} (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'linux-arm64-single.pubxml',
onTap: () => beginDownload(context, 'linux-arm64-single.pubxml'),
),
Expand All @@ -168,19 +189,28 @@ Widget getDownloadList(BuildContext context) {
SizedBox(height: tilesPadding),
StandardPlatformItem(
title: 'MacOS',
subTitle: 'Tested on MacOS Monterey',
subTitle: 'Download_Tested'.tr.replaceAll(
'%content%',
'MacOS Monterey',
),
leading: const Icon(CommunityMaterialIcons.apple),
onTap: () => showItemsDialog(
context,
[
StandardDownloadItem(
title: '适用于 MacOS 64 位 (Apple 芯片) (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'MacOS ${'Bits_64'.tr} (${'CPU_Apple'.tr}) (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'osx-arm64-single.pubxml',
onTap: () => beginDownload(context, 'osx-arm64-single.pubxml'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 MacOS 64 位 (Intel 芯片) (包含 dotnet 6 运行时)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'MacOS ${'Bits_64'.tr} (${'CPU_Intel'.tr}) (${'With_Runtime'.tr.replaceAll('%runtime%', 'dotnet 6')})',
),
subTitle: 'osx-x64-single.pubxml',
onTap: () => beginDownload(context, 'osx-x64-single.pubxml'),
),
Expand All @@ -190,31 +220,46 @@ Widget getDownloadList(BuildContext context) {
SizedBox(height: tilesPadding),
StandardPlatformItem(
title: 'Android',
subTitle: 'Android 5.0+ supported',
subTitle: 'Download_Supported'.tr.replaceAll(
'%content%',
'Android 5.0+',
),
leading: const Icon(CommunityMaterialIcons.android),
onTap: () => showItemsDialog(
context,
[
StandardDownloadItem(
title: '适用于 Android (包含多个架构支持)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Android (${'MultiArchSupport'.tr})',
),
subTitle: 'kitx-mobile-release.apk',
onTap: () => beginDownload(context, 'kitx-mobile-release.apk'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 Android arm 架构 64 位处理器 (ABIv8)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Android ${'CPU_ARM64'.tr} (ABIv8)',
),
subTitle: 'kitx-mobile-arm64-v8a-release.apk',
onTap: () => beginDownload(context, 'kitx-mobile-arm64-v8a-release.apk'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 Android arm 架构处理器 (ABIv7)',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Android ${'CPU_ARM'.tr} (ABIv7)',
),
subTitle: 'kitx-mobile-armeabi-v7a-release.apk',
onTap: () => beginDownload(context, 'kitx-mobile-armeabi-v7a-release.apk'),
),
SizedBox(height: tilesPadding),
StandardDownloadItem(
title: '适用于 Android x86 架构处理器 64 位',
title: 'Download_ApplyTo'.tr.replaceAll(
'%content%',
'Android ${'CPU_x86_64'.tr}',
),
subTitle: 'kitx-mobile-x86_64-release.apk',
onTap: () => beginDownload(context, 'kitx-mobile-x86_64-release.apk'),
),
Expand All @@ -225,7 +270,7 @@ Widget getDownloadList(BuildContext context) {
StandardPlatformItem(
enabled: false,
title: 'iOS',
subTitle: 'No test yet',
subTitle: 'Download_NoTest'.tr,
leading: const Icon(CommunityMaterialIcons.apple_ios),
onTap: () {},
),
Expand Down
Expand Up @@ -23,8 +23,8 @@ List<Widget> getActions(BuildContext context) => [
children: [
const Icon(CommunityMaterialIcons.file_document),
const SizedBox(width: 10),
const Text(
'Docs',
Text(
'Public_Docs'.tr,
style: TextStyle(fontSize: 16),
),
],
Expand Down Expand Up @@ -77,9 +77,11 @@ List<Widget> getActions(BuildContext context) => [
itemBuilder: (context) => [
PopupMenuItem(
child: const Text('简体中文'),
onTap: () => Global.delay(() => Get.updateLocale(Locale('zh', 'CN')), 200),
),
PopupMenuItem(
child: const Text('English (US)'),
onTap: () => Global.delay(() => Get.updateLocale(Locale('en', 'US')), 200),
),
],
),
Expand Down
46 changes: 46 additions & 0 deletions KitX Website Flutter/kitx_website/lib/utils/translations.dart
@@ -0,0 +1,46 @@
import 'package:get/get.dart';

/// Translation Data
class Translation extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'zh_CN': {
'Public_Docs': '文档',
'Download_Tested': '在 %content% 上通过测试',
'Download_Supported': '支持 %content%',
'Download_NoTest': '尚未测试',
'Download_ApplyTo': '适用于 %content%',
'Bits_32': '32 位',
'Bits_64': '64 位',
'CPU_Bits_32': '32 位处理器',
'CPU_Bits_64': '64 位处理器',
'CPU_x86': 'x86 架构处理器',
'CPU_x86_64': 'x86 架构 64 位处理器',
'CPU_ARM': 'arm 架构处理器',
'CPU_ARM64': 'arm 架构 64 位处理器',
'CPU_Intel': 'Intel 芯片',
'CPU_Apple': 'Apple 芯片',
'With_Runtime': '包含 %runtime% 运行时',
'MultiArchSupport': '包含多个架构支持',
},
'en_US': {
'Public_Docs': 'Docs',
'Download_Tested': 'Tested on %content%',
'Download_Supported': '%content% supported',
'Download_NoTest': 'No test yet',
'Download_ApplyTo': 'Apply to %content%',
'Bits_32': '32 bits',
'Bits_64': '64 bits',
'CPU_Bits_32': '32 bits CPU',
'CPU_Bits_64': '64 bits CPU',
'CPU_x86': 'x86 CPU',
'CPU_x86_64': 'x86 CPU 64 bits',
'CPU_ARM': 'arm CPU',
'CPU_ARM64': 'arm CPU 64 bits',
'CPU_Intel': 'Intel CPU',
'CPU_Apple': 'Apple CPU',
'With_Runtime': 'with %runtime% runtime',
'MultiArchSupport': 'Support multi architectures',
}
};
}

0 comments on commit 36f3ed7

Please sign in to comment.