Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
refactor(extensions_page): show extension language
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 1, 2021
1 parent e29fa19 commit dff70e0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cli/commands/generator/run/tasks/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ${Object.keys(languages)
extension LanguageCodesUtils on LanguageCodes {
String get code => name.replaceFirst(RegExp(r'_$'), '');
String get language => LanguageCodesUtils.codeNameMap[this]!;
String get language => LanguageUtils.codeNameMap[this]!;
}
abstract class LanguageUtils {
Expand Down Expand Up @@ -130,7 +130,7 @@ ${Object.keys(countries)
extension CountryCodesUtils on CountryCodes {
String get code => name.replaceFirst(RegExp(r'_$'), '');
String get language => CountryCodesUtils.codeNameMap[this]!;
String get country => CountryUtils.codeNameMap[this]!;
}
abstract class CountryUtils {
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/utils/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ abstract class ListUtils {
return chunked;
}

static List<T> insertBetween<T>(final List<T> elements, final T insert) {
static List<T> insertBetween<T>(final List<T> elements, final T filler) {
final List<T> inserted = <T>[];
final int size = elements.length;
for (int i = 0; i < size; i++) {
if (i != 0 && i < size) {
inserted.add(insert);
}
inserted.add(elements[i]);
if (i < size - 1) {
inserted.add(filler);
}
}
return inserted;
}
Expand Down
69 changes: 47 additions & 22 deletions lib/ui/pages/store_page/extensions_page/extensions_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class _ExtensionsPageState extends State<ExtensionsPage> {
Expanded(
child: RichText(
text: TextSpan(
children: <TextSpan>[
children: <InlineSpan>[
TextSpan(
text: ext.name,
text: '${ext.name}\n',
style: Theme.of(context)
.textTheme
.headline6
Expand All @@ -102,20 +102,30 @@ class _ExtensionsPageState extends State<ExtensionsPage> {
),
),
TextSpan(
text:
'\n${StringUtils.capitalize(ext.type.type)}${ext.nsfw ? '(18+)' : ''}',
style: Theme.of(context).textTheme.caption,
),
if (ext.nsfw)
TextSpan(
text: ' (${Translator.t.nsfw()})',
style: Theme.of(context)
.textTheme
.caption
?.copyWith(
color: Colors.red.shade400,
children: ListUtils.insertBetween(
<InlineSpan>[
TextSpan(
text: StringUtils.capitalize(
ext.type.type,
),
),
TextSpan(
text:
ext.defaultLocale.toPrettyString(),
),
if (ext.nsfw)
TextSpan(
text: Translator.t.nsfw(),
style: TextStyle(
color: Colors.red.shade400,
fontWeight: FontWeight.bold,
),
),
],
const TextSpan(text: ' — '),
),
style: Theme.of(context).textTheme.caption,
),
],
),
),
Expand Down Expand Up @@ -192,29 +202,44 @@ class _ExtensionPopupState extends State<_ExtensionPopup> {
),
),
SizedBox(
width: remToPx(0.7),
width: remToPx(1),
),
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: widget.ext.name,
style:
Theme.of(context).textTheme.headline6?.copyWith(
fontWeight: FontWeight.bold,
),
style: FunctionUtils.withValue(
Theme.of(context).textTheme.headline6,
(final TextStyle? style) => style?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
if (widget.ext.nsfw)
TextSpan(
text: ' (${Translator.t.nsfw()})',
style: FunctionUtils.withValue(
Theme.of(context).textTheme.bodyText2,
(final TextStyle? style) => style?.copyWith(
color: Colors.red.shade400,
fontWeight: FontWeight.bold,
),
),
),
TextSpan(
text: '\n${Translator.t.by()} ${widget.ext.author}',
),
TextSpan(
text:
'\n${Translator.t.by()} ${widget.ext.id.split('.').first}',
style: Theme.of(context).textTheme.caption,
'\n${Translator.t.language()}: ${widget.ext.defaultLocale.toPrettyString()}',
),
TextSpan(
text:
'\n${Translator.t.version()}: ${widget.ext.version.toString()}',
style: Theme.of(context).textTheme.caption,
),
],
style: Theme.of(context).textTheme.caption,
),
),
],
Expand Down
8 changes: 4 additions & 4 deletions packages/utilx/lib/generated/locale.g.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SHA: 578ed4fc4a128f6bf75acb5bce8b48ce0dba489d
// ID: MTYzNTc3NjgwNDczOS4wNDk2LTE2MzU3NzY4MDQ3MzkuMDQ5Ng==
// SHA: f5800e351bb4dc722698a4ef2b894b3ff44f773c
// ID: MTYzNTc3OTE0OTExMi4yOTE3LTE2MzU3NzkxNDkxMTIuMjkxNw==
// Generated file. Do not edit.

enum LanguageCodes {
Expand Down Expand Up @@ -190,7 +190,7 @@ enum LanguageCodes {

extension LanguageCodesUtils on LanguageCodes {
String get code => name.replaceFirst(RegExp(r'_$'), '');
String get language => LanguageCodesUtils.codeNameMap[this]!;
String get language => LanguageUtils.codeNameMap[this]!;
}

abstract class LanguageUtils {
Expand Down Expand Up @@ -636,7 +636,7 @@ enum CountryCodes {

extension CountryCodesUtils on CountryCodes {
String get code => name.replaceFirst(RegExp(r'_$'), '');
String get language => CountryCodesUtils.codeNameMap[this]!;
String get country => CountryUtils.codeNameMap[this]!;
}

abstract class CountryUtils {
Expand Down
5 changes: 5 additions & 0 deletions packages/utilx/lib/utilities/locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Locale {
return threshold;
}

String toPrettyString() => <String>[
code.language,
if (country != null) '(${country!.country})'
].join(' ');

@override
String toString() =>
<String>[code.code, if (country != null) country!.code].join('_');
Expand Down

0 comments on commit dff70e0

Please sign in to comment.