fix: 修复语言设置为简体中文而非繁体翻译
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -426,7 +424,6 @@ class _ResultHeader extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return Row(
|
||||
children: [
|
||||
@@ -436,29 +433,6 @@ class _ResultHeader extends StatelessWidget {
|
||||
context,
|
||||
).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final payload = <String, dynamic>{
|
||||
'signType': data.signType,
|
||||
'question': data.params.question,
|
||||
'keywords': data.keywords,
|
||||
'conclusion': data.conclusion,
|
||||
};
|
||||
Clipboard.setData(
|
||||
ClipboardData(
|
||||
text: const JsonEncoder.withIndent(' ').convert(payload),
|
||||
),
|
||||
);
|
||||
Toast.show(
|
||||
context,
|
||||
l10n.toastContentCopied,
|
||||
type: ToastType.success,
|
||||
);
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: colors.primary),
|
||||
child: Text(l10n.resultShare),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -799,6 +773,8 @@ class _HexagramDetailCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final isTraditionalChinese =
|
||||
Localizations.localeOf(context).scriptCode == 'Hant';
|
||||
return Column(
|
||||
children: [
|
||||
Card(
|
||||
@@ -826,14 +802,14 @@ class _HexagramDetailCard extends StatelessWidget {
|
||||
Expanded(
|
||||
child: _miniKV(
|
||||
context,
|
||||
DivinationTerms.yueJian,
|
||||
l10n.termYueJian,
|
||||
data.ganzhi.yueJian,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _miniKV(
|
||||
context,
|
||||
DivinationTerms.riChen,
|
||||
l10n.termRiChen,
|
||||
data.ganzhi.riChen,
|
||||
),
|
||||
),
|
||||
@@ -845,14 +821,14 @@ class _HexagramDetailCard extends StatelessWidget {
|
||||
Expanded(
|
||||
child: _miniKV(
|
||||
context,
|
||||
DivinationTerms.yuePo,
|
||||
l10n.termYuePo,
|
||||
data.ganzhi.yuePo,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _miniKV(
|
||||
context,
|
||||
DivinationTerms.riChong,
|
||||
l10n.termRiChong,
|
||||
data.ganzhi.riChong,
|
||||
),
|
||||
),
|
||||
@@ -898,7 +874,11 @@ class _HexagramDetailCard extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
data.guaName,
|
||||
_toTraditionalGuaNameIfNeeded(
|
||||
data.guaName,
|
||||
isTraditionalChinese,
|
||||
l10n,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.w700),
|
||||
@@ -907,7 +887,11 @@ class _HexagramDetailCard extends StatelessWidget {
|
||||
if (data.hasChangingYao)
|
||||
Expanded(
|
||||
child: Text(
|
||||
data.targetGuaName,
|
||||
_toTraditionalGuaNameIfNeeded(
|
||||
data.targetGuaName,
|
||||
isTraditionalChinese,
|
||||
l10n,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.w700),
|
||||
@@ -943,6 +927,24 @@ class _HexagramDetailCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
String _toTraditionalGuaNameIfNeeded(
|
||||
String value,
|
||||
bool isTraditionalChinese,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
if (!isTraditionalChinese || value.isEmpty) {
|
||||
return value;
|
||||
}
|
||||
final from = l10n.guaNameSimplifiedChars;
|
||||
final to = l10n.guaNameTraditionalChars;
|
||||
final map = <String, String>{};
|
||||
final length = from.length < to.length ? from.length : to.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
map[from[i]] = to[i];
|
||||
}
|
||||
return value.split('').map((char) => map[char] ?? char).join();
|
||||
}
|
||||
|
||||
class _WuXingTable extends StatelessWidget {
|
||||
const _WuXingTable({required this.data});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user