feat(i18n): full RTL/CJK support — fonts, Japanese locale, directional fixes
Bundle Noto Sans Arabic + Noto Sans JP (SIL OFL 1.1) as per-glyph fallbacks for both the UI text theme and every generated PDF, so RTL (Arabic) and CJK render on all platforms — including desktop, where the system font may lack them — instead of tofu. A shared pdf_fonts.dart centralizes the PDF theme and the three label/catalog/recovery services reuse it. Add Japanese (ja) as the CJK reference locale — fittingly, the app's own name is Japanese (種, tane, 'seed'). Core strings translated; the rest fall back to English via slang. Wired into supportedLocales (automatic) and the settings picker. Fix three physical Alignment.centerLeft -> AlignmentDirectional.centerStart in variety_detail_screen, and make month-abbreviation and avatar-initial truncation grapheme-safe (.characters) so CJK text is never cut mid-character. Tests: CJK/Arabic PDF glyph render, ja locale resolution + English fallback. The chat-bubble mirroring flagged by the audit was verified correct (already respects Directionality) and left unchanged.
This commit is contained in:
parent
fe4591d747
commit
7ae6becd8f
31 changed files with 686 additions and 104 deletions
31
apps/app_seeds/test/services/i18n_ja_locale_test.dart
Normal file
31
apps/app_seeds/test/services/i18n_ja_locale_test.dart
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/i18n/strings.g.dart';
|
||||
|
||||
/// Japanese (`ja`) is the CJK reference locale — fitting, since the app's own
|
||||
/// name is Japanese (種, *tane*, "seed"). It proves the CJK path end to end:
|
||||
/// the locale is wired, core strings resolve in Japanese, and untranslated
|
||||
/// keys fall back to the English base (slang `fallback_strategy: base_locale`).
|
||||
void main() {
|
||||
test('ja is a supported locale', () {
|
||||
expect(
|
||||
AppLocaleUtils.supportedLocales.map((l) => l.languageCode),
|
||||
contains('ja'),
|
||||
);
|
||||
});
|
||||
|
||||
test('core strings resolve in Japanese', () {
|
||||
final ja = AppLocale.ja.buildSync();
|
||||
expect(ja.menu.inventory, '在庫');
|
||||
expect(ja.common.save, '保存');
|
||||
expect(ja.settings.langJa, '日本語');
|
||||
});
|
||||
|
||||
test('untranslated keys fall back to the English base', () {
|
||||
final ja = AppLocale.ja.buildSync();
|
||||
final en = AppLocale.en.buildSync();
|
||||
// `menu.plantares` is left untranslated in ja (a coined feature name), so
|
||||
// it must surface the English text rather than a blank or a key.
|
||||
expect(ja.menu.plantares, en.menu.plantares);
|
||||
expect(ja.menu.plantares, isNotEmpty);
|
||||
});
|
||||
}
|
||||
|
|
@ -76,6 +76,27 @@ void main() {
|
|||
expect(String.fromCharCodes(bytes.take(5)), '%PDF-');
|
||||
});
|
||||
|
||||
test('buildPdf embeds CJK and Arabic glyphs (no tofu)', () async {
|
||||
// Japanese (CJK) and Arabic (RTL) fall outside DejaVu's coverage; the Noto
|
||||
// fallbacks in the PDF theme must render them without throwing. Guards
|
||||
// against a regression that drops the fallback fonts.
|
||||
final service = LabelSheetService(files: _RecordingFileService());
|
||||
final bytes = await service.buildPdf(
|
||||
labels: const [
|
||||
LabelSheetLabel(
|
||||
varietyLabel: '日本の在来種のトマト',
|
||||
commonName: 'トマト',
|
||||
scientificName: 'Solanum lycopersicum',
|
||||
qrData: 'tane://seed?v=tomato',
|
||||
),
|
||||
LabelSheetLabel(varietyLabel: 'طماطم بلدية', qrData: 'tane://seed?v=x'),
|
||||
],
|
||||
format: LabelSheetFormat.cards,
|
||||
);
|
||||
expect(String.fromCharCodes(bytes.take(5)), '%PDF-');
|
||||
expect(bytes.length, greaterThan(1000));
|
||||
});
|
||||
|
||||
test('saveLabels hands the PDF to the save dialog', () async {
|
||||
final files = _RecordingFileService();
|
||||
final service = LabelSheetService(files: files);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue