diff --git a/feedback/lib/src/l18n/translation.dart b/feedback/lib/src/l18n/translation.dart index 2d62e03b..ea989b22 100644 --- a/feedback/lib/src/l18n/translation.dart +++ b/feedback/lib/src/l18n/translation.dart @@ -228,6 +228,24 @@ class ZhFeedbackLocalizations extends FeedbackLocalizations { String get navigate => '导航'; } +/// Default Simplified Chinese localization +class ZhTWFeedbackLocalizations extends FeedbackLocalizations { + /// Creates a [ZhTWFeedbackLocalizations]. + const ZhTWFeedbackLocalizations(); + + @override + String get submitButtonText => '提交'; + + @override + String get feedbackDescriptionText => '敬請留下您寶貴的意見和建議:'; + + @override + String get draw => '標記'; + + @override + String get navigate => '切換頁面'; +} + /// Default polish localization class PlFeedbackLocalizations extends FeedbackLocalizations { /// Creates a [PlFeedbackLocalizations]. @@ -261,7 +279,7 @@ class PtFeedbackLocalizations extends FeedbackLocalizations { String get draw => 'Desenhar'; @override - String get navigate => 'Navegar'; + String get navigate => '瀏覽頁面'; } /// Default japanese localization @@ -361,6 +379,7 @@ class GlobalFeedbackLocalizationsDelegate const Locale('uk'): const UkFeedbackLocalizations(), const Locale('tr'): const TrFeedbackLocalizations(), const Locale('zh'): const ZhFeedbackLocalizations(), + const Locale('zh', 'TW'): const ZhTWFeedbackLocalizations(), const Locale('pl'): const PlFeedbackLocalizations(), const Locale('pt'): const PtFeedbackLocalizations(), const Locale('ja'): const JaFeedbackLocalizations(), @@ -389,8 +408,12 @@ class GlobalFeedbackLocalizationsDelegate @override Future load(Locale locale) { - final languageLocale = Locale(locale.languageCode); - // We only support language codes for now + Locale languageLocale; + if (supportedLocales.containsKey(locale)) { + languageLocale = locale; + } else { + languageLocale = Locale(locale.languageCode); + } return SynchronousFuture( supportedLocales[languageLocale] ?? supportedLocales[defaultLocale]!, ); diff --git a/feedback/test/l18n/feedback_l18n_test.dart b/feedback/test/l18n/feedback_l18n_test.dart new file mode 100644 index 00000000..c07d4bf0 --- /dev/null +++ b/feedback/test/l18n/feedback_l18n_test.dart @@ -0,0 +1,21 @@ +import 'package:feedback/feedback.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('overwrites locale', () async { + const language = Locale('zh', 'TW'); + final GlobalFeedbackLocalizationsDelegate delegate = + GlobalFeedbackLocalizationsDelegate(); + final FeedbackLocalizations localizations = await delegate.load(language); + const ZhTWFeedbackLocalizations targetLocalizations = + ZhTWFeedbackLocalizations(); + // ensure overrides apply + expect(localizations.draw, targetLocalizations.draw); + expect(localizations.navigate, targetLocalizations.navigate); + expect( + localizations.submitButtonText, targetLocalizations.submitButtonText); + expect(localizations.feedbackDescriptionText, + targetLocalizations.feedbackDescriptionText); + }); +}