Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions feedback/lib/src/l18n/translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -261,7 +279,7 @@ class PtFeedbackLocalizations extends FeedbackLocalizations {
String get draw => 'Desenhar';

@override
String get navigate => 'Navegar';
String get navigate => '瀏覽頁面';
}

/// Default japanese localization
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -389,8 +408,12 @@ class GlobalFeedbackLocalizationsDelegate

@override
Future<FeedbackLocalizations> 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<FeedbackLocalizations>(
supportedLocales[languageLocale] ?? supportedLocales[defaultLocale]!,
);
Expand Down
21 changes: 21 additions & 0 deletions feedback/test/l18n/feedback_l18n_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}