feat: ship the interface in eight languages, with per-language plurals and mirroring
This commit is contained in:
parent
6de6672ae3
commit
a4a49f41d7
28 changed files with 1795 additions and 32 deletions
|
|
@ -196,25 +196,35 @@ ListBlock itemList(List<MewsListItem> items) =>
|
|||
/// Wraps blocks as an internal document. The marker makes the renderer treat
|
||||
/// it as a Mews page rather than prepending the "not a Mews page" notice, and
|
||||
/// no entries are offered so an internal page is never subscribable.
|
||||
///
|
||||
/// Unlike a fetched page, which declares its own language, one of ours is
|
||||
/// written in whichever language the reader set, so it takes its direction
|
||||
/// from that and mirrors when the interface does.
|
||||
MewsPage internalPage({
|
||||
required Uri url,
|
||||
required String title,
|
||||
required List<MewsBlock> body,
|
||||
required Strings strings,
|
||||
}) {
|
||||
return MewsPage(
|
||||
url: url.toString(),
|
||||
specVersion: 'internal',
|
||||
title: title,
|
||||
body: body,
|
||||
lang: 'en',
|
||||
direction: TextDirection.ltr,
|
||||
lang: strings.tag,
|
||||
direction: strings.isRtl ? TextDirection.rtl : TextDirection.ltr,
|
||||
variant: MewsVariant.plain,
|
||||
entries: const [],
|
||||
);
|
||||
}
|
||||
|
||||
/// Picks the message for [count]. Plurals are separate messages, so the
|
||||
/// choice happens here and Fluent formats the number.
|
||||
/// Picks the message for [count]. Plurals are separate messages rather than a
|
||||
/// rule inside one, so the choice happens here.
|
||||
///
|
||||
/// A language needing a form English does not have, such as Russian's "few"
|
||||
/// or Hebrew's "two", names it with the same id and that suffix. Those are
|
||||
/// derived from [many] rather than passed at every call, and a language
|
||||
/// without them falls through to [many].
|
||||
String countText(
|
||||
Strings strings,
|
||||
int count, {
|
||||
|
|
@ -222,11 +232,15 @@ String countText(
|
|||
required String one,
|
||||
required String many,
|
||||
}) {
|
||||
return switch (count) {
|
||||
0 => strings.t(none),
|
||||
1 => strings.t(one),
|
||||
_ => strings.t(many, {'count': count}),
|
||||
};
|
||||
if (count == 0) return strings.t(none);
|
||||
final suffix = strings.pluralSuffixFor(count);
|
||||
if (suffix == 'one') return strings.t(one, {'count': count});
|
||||
if (suffix != 'many') {
|
||||
final stem = many.substring(0, many.lastIndexOf('-'));
|
||||
final text = strings.lookup('$stem-$suffix', {'count': count});
|
||||
if (text != null) return text;
|
||||
}
|
||||
return strings.t(many, {'count': count});
|
||||
}
|
||||
|
||||
/// YYYY-MM-DD, the shape a Mews entry link uses (spec 6.1).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue