From fd2eb5cda6c8d2a567cac18da0cf559551b1f71a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 22 Dec 2024 15:20:33 +0800 Subject: [PATCH] :sparkles: Localized post categories --- assets/translations/en-US.json | 12 ++++- assets/translations/zh-CN.json | 12 ++++- assets/translations/zh-HK.json | 12 ++++- assets/translations/zh-TW.json | 12 ++++- lib/widgets/post/post_item.dart | 7 ++- lib/widgets/post/post_tags_field.dart | 78 ++++++++++++++------------- 6 files changed, 90 insertions(+), 43 deletions(-) diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index 601ff58..631151e 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -478,5 +478,15 @@ "colorSchemeRed": "Red", "colorSchemeWhite": "White", "colorSchemeBlack": "Black", - "colorSchemeApplied": "Color scheme has been applied, may need restart the app to take effect." + "colorSchemeApplied": "Color scheme has been applied, may need restart the app to take effect.", + "postCategoryTechnology": "Technology", + "postCategoryGaming": "Gaming", + "postCategoryLife": "Life", + "postCategoryArts": "Arts", + "postCategorySports": "Sports", + "postCategoryMusic": "Music", + "postCategoryNews": "News", + "postCategoryKnowledge": "Knowledge", + "postCategoryLiterature": "Literature", + "postCategoryUncategorized": "Uncategorized" } diff --git a/assets/translations/zh-CN.json b/assets/translations/zh-CN.json index 0ad7b16..c693658 100644 --- a/assets/translations/zh-CN.json +++ b/assets/translations/zh-CN.json @@ -476,5 +476,15 @@ "colorSchemeRed": "红色", "colorSchemeWhite": "白色", "colorSchemeBlack": "黑色", - "colorSchemeApplied": "主题色已应用,可能需要重启来生效。" + "colorSchemeApplied": "主题色已应用,可能需要重启来生效。", + "postCategoryTechnology": "技术", + "postCategoryGaming": "游戏", + "postCategoryLife": "生活", + "postCategoryArts": "艺术", + "postCategorySports": "体育", + "postCategoryMusic": "音乐", + "postCategoryNews": "新闻", + "postCategoryKnowledge": "知识", + "postCategoryLiterature": "文学", + "postCategoryUncategorized": "未分类" } diff --git a/assets/translations/zh-HK.json b/assets/translations/zh-HK.json index b7edfa4..e1c2bc0 100644 --- a/assets/translations/zh-HK.json +++ b/assets/translations/zh-HK.json @@ -476,5 +476,15 @@ "colorSchemeRed": "紅色", "colorSchemeWhite": "白色", "colorSchemeBlack": "黑色", - "colorSchemeApplied": "主題色已應用,可能需要重啓來生效。" + "colorSchemeApplied": "主題色已應用,可能需要重啓來生效。", + "postCategoryTechnology": "技術", + "postCategoryGaming": "遊戲", + "postCategoryLife": "生活", + "postCategoryArts": "藝術", + "postCategorySports": "體育", + "postCategoryMusic": "音樂", + "postCategoryNews": "新聞", + "postCategoryKnowledge": "知識", + "postCategoryLiterature": "文學", + "postCategoryUncategorized": "未分類" } diff --git a/assets/translations/zh-TW.json b/assets/translations/zh-TW.json index b1c0b7a..d28e6b2 100644 --- a/assets/translations/zh-TW.json +++ b/assets/translations/zh-TW.json @@ -476,5 +476,15 @@ "colorSchemeRed": "紅色", "colorSchemeWhite": "白色", "colorSchemeBlack": "黑色", - "colorSchemeApplied": "主題色已應用,可能需要重啟來生效。" + "colorSchemeApplied": "主題色已應用,可能需要重啟來生效。", + "postCategoryTechnology": "技術", + "postCategoryGaming": "遊戲", + "postCategoryLife": "生活", + "postCategoryArts": "藝術", + "postCategorySports": "體育", + "postCategoryMusic": "音樂", + "postCategoryNews": "新聞", + "postCategoryKnowledge": "知識", + "postCategoryLiterature": "文學", + "postCategoryUncategorized": "未分類" } diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 9d44a6e..5c0e4aa 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -981,7 +981,12 @@ class _PostTagsList extends StatelessWidget { children: [ const Icon(Symbols.category, size: 20), const Gap(4), - Text(ele.alias, style: GoogleFonts.robotoMono()), + Text( + 'postCategory${ele.alias.capitalize()}'.trExists() + ? 'postCategory${ele.alias.capitalize()}'.tr() + : ele.alias, + style: GoogleFonts.robotoMono(), + ), ], ), onTap: () {}, diff --git a/lib/widgets/post/post_tags_field.dart b/lib/widgets/post/post_tags_field.dart index 7b6c167..0b8b57c 100644 --- a/lib/widgets/post/post_tags_field.dart +++ b/lib/widgets/post/post_tags_field.dart @@ -1,9 +1,11 @@ import 'dart:async'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; import 'package:provider/provider.dart'; import 'package:surface/providers/sn_network.dart'; +import 'package:surface/widgets/dialog.dart'; class PostTagsField extends StatefulWidget { final List? initialTags; @@ -100,8 +102,7 @@ class _PostTagsFieldState extends State { color: Theme.of(context).colorScheme.primary, ), margin: const EdgeInsets.only(right: 8), - padding: const EdgeInsets.symmetric( - horizontal: 10.0, vertical: 4.0), + padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -237,46 +238,47 @@ class _PostCategoriesFieldState extends State { ), prefixIcon: _currentCategories.isNotEmpty ? SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: _currentCategories.map((String category) { - return Container( - decoration: BoxDecoration( - borderRadius: const BorderRadius.all( - Radius.circular(20.0), - ), - color: Theme.of(context).colorScheme.primary, - ), - margin: const EdgeInsets.only(right: 8), - padding: const EdgeInsets.symmetric( - horizontal: 10.0, vertical: 4.0), + scrollDirection: Axis.horizontal, child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - InkWell( - child: Text( - '#$category', - style: const TextStyle(color: Colors.white), + children: _currentCategories.map((String category) { + return Container( + decoration: BoxDecoration( + borderRadius: const BorderRadius.all( + Radius.circular(20.0), + ), + color: Theme.of(context).colorScheme.primary, ), - ), - const Gap(4), - InkWell( - child: const Icon( - Icons.cancel, - size: 14.0, - color: Color.fromARGB(255, 233, 233, 233), + margin: const EdgeInsets.only(right: 8), + padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + InkWell( + child: Text( + 'postCategory${category.capitalize()}'.trExists() + ? 'postCategory${category.capitalize()}'.tr() + : '#$category', + style: const TextStyle(color: Colors.white), + ), + ), + const Gap(4), + InkWell( + child: const Icon( + Icons.cancel, + size: 14.0, + color: Color.fromARGB(255, 233, 233, 233), + ), + onTap: () { + setState(() => _currentCategories.remove(category)); + widget.onUpdate(_currentCategories); + }, + ) + ], ), - onTap: () { - setState(() => _currentCategories.remove(category)); - widget.onUpdate(_currentCategories); - }, - ) - ], + ); + }).toList(), ), - ); - }).toList(), - ), - ) + ) : null, ), onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),