Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Add support for language selection

AmanRajSinghMouryacb30e56fe2f5
diff --git a/.github/workflows/locker-crowdin-push.yml b/.github/workflows/locker-crowdin-push.yml
new file mode 100644
index 0000000000..0974712b2e
--- /dev/null
+++ b/.github/workflows/locker-crowdin-push.yml
@@ -0,0 +1,36 @@
+name: "Push sources to Crowdin (locker)"
+
+on:
+ push:
+ branches: [main]
+ paths:
+ # Run workflow when locker's app_en.arb is changed
+ - "mobile/apps/locker/lib/l10n/app_en.arb"
+ # Or the workflow itself is changed
+ - ".github/workflows/locker-crowdin-push.yml"
+
+permissions:
+ contents: write
+ pull-requests: write
+
+jobs:
+ push-sources-to-crowdin:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Crowdin's action
+ uses: crowdin/github-action@v2
+ with:
+ base_path: "mobile/apps/locker/"
+ config: "mobile/apps/locker/crowdin.yml"
+ upload_sources: true
+ upload_translations: false
+ download_translations: false
+ # TODO: Replace with actual Crowdin project ID after creating the project
+ project_id: ${{ vars.CROWDIN_LOCKER_PROJECT_ID }}
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
diff --git a/.github/workflows/locker-crowdin-sync.yml b/.github/workflows/locker-crowdin-sync.yml
new file mode 100644
index 0000000000..6c23546728
--- /dev/null
+++ b/.github/workflows/locker-crowdin-sync.yml
@@ -0,0 +1,41 @@
+name: "Sync Crowdin translations (locker)"
+
+on:
+ schedule:
+ # Run Mondays at ~7:00 AM IST
+ # See: [Note: Run workflow on specific days of the week]
+ - cron: "30 1 * * 1"
+ # Also allow manually running the workflow.
+ workflow_dispatch:
+
+permissions:
+ contents: write
+ pull-requests: write
+
+jobs:
+ synchronize-with-crowdin:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Crowdin's action
+ uses: crowdin/github-action@v2
+ with:
+ base_path: "mobile/apps/locker/"
+ config: "mobile/apps/locker/crowdin.yml"
+ upload_sources: true
+ upload_translations: false
+ download_translations: true
+ localization_branch_name: translations/locker
+ create_pull_request: true
+ skip_untranslated_strings: true
+ pull_request_title: "[locker] New translations"
+ pull_request_body: "New translations from [Crowdin](https://crowdin.com/project/ente-locker-app)"
+ pull_request_base_branch_name: "main"
+ # TODO: Replace with actual Crowdin project ID after creating the project
+ project_id: ${{ vars.CROWDIN_LOCKER_PROJECT_ID }}
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
diff --git a/mobile/apps/locker/crowdin.yml b/mobile/apps/locker/crowdin.yml
new file mode 100644
index 0000000000..58ed86003c
--- /dev/null
+++ b/mobile/apps/locker/crowdin.yml
@@ -0,0 +1,5 @@
+api_token_env: CROWDIN_PERSONAL_TOKEN
+
+files:
+ - source: /lib/l10n/app_en.arb
+ translation: /lib/l10n/app_%two_letters_code%.arb
diff --git a/mobile/apps/locker/lib/l10n/app_en.arb b/mobile/apps/locker/lib/l10n/app_en.arb
index 77df05fd29..afec68a735 100644
--- a/mobile/apps/locker/lib/l10n/app_en.arb
+++ b/mobile/apps/locker/lib/l10n/app_en.arb
@@ -901,5 +901,8 @@
"removeAccess": "Remove access",
"subscriptionRequiredForSharing": "You need a paid subscription to share links",
"sessionExpired": "Session expired",
- "pleaseLoginAgain": "Please login again"
+ "pleaseLoginAgain": "Please login again",
+ "language": "Language",
+ "selectLanguage": "Select language",
+ "general": "General"
}
diff --git a/mobile/apps/locker/lib/l10n/app_localizations.dart b/mobile/apps/locker/lib/l10n/app_localizations.dart
index 6f740efdc6..a731cb7773 100644
--- a/mobile/apps/locker/lib/l10n/app_localizations.dart
+++ b/mobile/apps/locker/lib/l10n/app_localizations.dart
@@ -2661,6 +2661,24 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Please login again'**
String get pleaseLoginAgain;
+
+ /// No description provided for @language.
+ ///
+ /// In en, this message translates to:
+ /// **'Language'**
+ String get language;
+
+ /// No description provided for @selectLanguage.
+ ///
+ /// In en, this message translates to:
+ /// **'Select language'**
+ String get selectLanguage;
+
+ /// No description provided for @general.
+ ///
+ /// In en, this message translates to:
+ /// **'General'**
+ String get general;
}
class _AppLocalizationsDelegate
diff --git a/mobile/apps/locker/lib/l10n/app_localizations_en.dart b/mobile/apps/locker/lib/l10n/app_localizations_en.dart
index eb79ba17b1..75c3643546 100644
--- a/mobile/apps/locker/lib/l10n/app_localizations_en.dart
+++ b/mobile/apps/locker/lib/l10n/app_localizations_en.dart
@@ -1551,4 +1551,13 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get pleaseLoginAgain => 'Please login again';
+
+ @override
+ String get language => 'Language';
+
+ @override
+ String get selectLanguage => 'Select language';
+
+ @override
+ String get general => 'General';
}
diff --git a/mobile/apps/locker/lib/ui/drawer/general_section_widget.dart b/mobile/apps/locker/lib/ui/drawer/general_section_widget.dart
new file mode 100644
index 0000000000..2cc3d6914b
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/drawer/general_section_widget.dart
@@ -0,0 +1,50 @@
+import "package:ente_utils/navigation_util.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:locker/app.dart";
+import "package:locker/core/locale.dart";
+import "package:locker/l10n/l10n.dart";
+import "package:locker/ui/components/expandable_menu_item_widget.dart";
+import "package:locker/ui/settings/language_selector_page.dart";
+
+class GeneralSectionWidget extends StatelessWidget {
+ const GeneralSectionWidget({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ return ExpandableMenuItemWidget(
+ title: l10n.general,
+ selectionOptionsWidget: _getSectionOptions(context),
+ leadingIcon: HugeIcons.strokeRoundedSettings01,
+ );
+ }
+
+ Column _getSectionOptions(BuildContext context) {
+ final l10n = context.l10n;
+
+ return Column(
+ children: [
+ ExpandableChildItem(
+ title: l10n.language,
+ trailingIcon: Icons.chevron_right,
+ onTap: () async {
+ final locale = await getLocale();
+ // ignore: unawaited_futures
+ routeToPage(
+ context,
+ LanguageSelectorPage(
+ appSupportedLocales,
+ (newLocale) async {
+ await setLocale(newLocale);
+ App.setLocale(context, newLocale);
+ },
+ locale ?? const Locale('en'),
+ ),
+ );
+ },
+ ),
+ ],
+ );
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/drawer/settings_widgets.dart b/mobile/apps/locker/lib/ui/drawer/settings_widgets.dart
index 1134c6b795..da365754f4 100644
--- a/mobile/apps/locker/lib/ui/drawer/settings_widgets.dart
+++ b/mobile/apps/locker/lib/ui/drawer/settings_widgets.dart
@@ -6,6 +6,7 @@ import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
import "package:locker/ui/drawer/about_section_widget.dart";
import "package:locker/ui/drawer/account_section_widget.dart";
+import "package:locker/ui/drawer/general_section_widget.dart";
import "package:locker/ui/drawer/security_section_widget.dart";
import "package:locker/ui/drawer/social_section_widget.dart";
import "package:locker/ui/drawer/support_section_widget.dart";
@@ -55,6 +56,11 @@ class SettingsWidgets extends StatelessWidget {
}
}
+ contents.addAll([
+ const GeneralSectionWidget(),
+ sectionSpacing,
+ ]);
+
contents.addAll([
const SupportSectionWidget(),
sectionSpacing,
diff --git a/mobile/apps/locker/lib/ui/settings/language_selector_page.dart b/mobile/apps/locker/lib/ui/settings/language_selector_page.dart
new file mode 100644
index 0000000000..8980313d18
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/settings/language_selector_page.dart
@@ -0,0 +1,246 @@
+import "package:ente_ui/components/captioned_text_widget.dart";
+import "package:ente_ui/components/divider_widget.dart";
+import "package:ente_ui/components/menu_item_widget.dart";
+import "package:ente_ui/components/separators.dart";
+import "package:ente_ui/components/title_bar_title_widget.dart";
+import "package:ente_ui/components/title_bar_widget.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:flutter/foundation.dart";
+import "package:flutter/material.dart";
+import "package:locker/l10n/l10n.dart";
+
+class LanguageSelectorPage extends StatelessWidget {
+ final List<Locale> supportedLocales;
+ final ValueChanged<Locale> onLocaleChanged;
+ final Locale currentLocale;
+
+ const LanguageSelectorPage(
+ this.supportedLocales,
+ this.onLocaleChanged,
+ this.currentLocale, {
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: CustomScrollView(
+ primary: false,
+ slivers: <Widget>[
+ TitleBarWidget(
+ flexibleSpaceTitle: TitleBarTitleWidget(
+ title: context.l10n.selectLanguage,
+ ),
+ ),
+ SliverList(
+ delegate: SliverChildBuilderDelegate(
+ (context, index) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 20,
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ClipRRect(
+ borderRadius:
+ const BorderRadius.all(Radius.circular(8)),
+ child: _LanguageItemsWidget(
+ supportedLocales,
+ onLocaleChanged,
+ currentLocale,
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ childCount: 1,
+ ),
+ ),
+ const SliverPadding(padding: EdgeInsets.symmetric(vertical: 12)),
+ ],
+ ),
+ );
+ }
+}
+
+class _LanguageItemsWidget extends StatefulWidget {
+ final List<Locale> supportedLocales;
+ final ValueChanged<Locale> onLocaleChanged;
+ final Locale currentLocale;
+
+ const _LanguageItemsWidget(
+ this.supportedLocales,
+ this.onLocaleChanged,
+ this.currentLocale,
+ );
+
+ @override
+ State<_LanguageItemsWidget> createState() => _LanguageItemsWidgetState();
+}
+
+class _LanguageItemsWidgetState extends State<_LanguageItemsWidget> {
+ late Locale currentLocale;
+
+ @override
+ void initState() {
+ currentLocale = widget.currentLocale;
+ super.initState();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ List<Widget> items = [];
+ for (Locale locale in widget.supportedLocales) {
+ items.add(_menuItemForPicker(locale));
+ }
+ items = addSeparators(
+ items,
+ DividerWidget(
+ dividerType: DividerType.menuNoIcon,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ );
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: items,
+ );
+ }
+
+ String _getLanguageName(Locale locale) {
+ switch (locale.languageCode) {
+ case 'ar':
+ return 'العربية';
+ case 'be':
+ return 'Беларуская';
+ case 'bg':
+ return 'Български';
+ case 'ca':
+ return 'Català';
+ case 'cs':
+ return 'Čeština';
+ case 'da':
+ return 'Dansk';
+ case 'de':
+ return 'Deutsch';
+ case 'el':
+ return 'Ελληνικά';
+ case 'en':
+ return 'English';
+ case 'es':
+ switch (locale.countryCode) {
+ case 'ES':
+ return 'Español (España)';
+ default:
+ return 'Español';
+ }
+ case 'et':
+ return 'Eesti';
+ case 'fa':
+ return 'فارسی';
+ case 'fi':
+ return 'Suomi';
+ case 'fr':
+ return 'Français';
+ case 'gu':
+ return 'ગુજરાતી';
+ case 'he':
+ return 'עברית';
+ case 'hi':
+ return 'हिन्दी';
+ case 'hu':
+ return 'Magyar';
+ case 'id':
+ return 'Bahasa Indonesia';
+ case 'it':
+ return 'Italiano';
+ case 'ja':
+ return '日本語';
+ case 'ka':
+ return 'ქართული';
+ case 'km':
+ return 'ភាសាខ្មែរ';
+ case 'ko':
+ return '한국어';
+ case 'lt':
+ return 'Lietuvių';
+ case 'lv':
+ return 'Latviešu';
+ case 'ml':
+ return 'മലയാളം';
+ case 'nl':
+ return 'Nederlands';
+ case 'no':
+ return 'Norsk';
+ case 'pl':
+ return 'Polski';
+ case 'pt':
+ switch (locale.countryCode) {
+ case 'BR':
+ return 'Português (Brasil)';
+ default:
+ return 'Português';
+ }
+ case 'ro':
+ return 'Română';
+ case 'ru':
+ return 'Русский';
+ case 'sk':
+ return 'Slovenčina';
+ case 'sl':
+ return 'Slovenščina';
+ case 'sr':
+ return 'Српски';
+ case 'sv':
+ return 'Svenska';
+ case 'ti':
+ return 'ትግርኛ';
+ case 'tr':
+ return 'Türkçe';
+ case 'uk':
+ return 'Українська';
+ case 'vi':
+ return 'Tiếng Việt';
+ case 'zh':
+ if (locale.countryCode == 'TW') {
+ return '中文 (台灣)';
+ } else if (locale.countryCode == 'HK') {
+ return '中文 (香港)';
+ } else if (locale.countryCode == 'CN') {
+ return '中文 (中国)';
+ }
+ switch (locale.scriptCode) {
+ case 'Hans':
+ return '中文 (简体)';
+ case 'Hant':
+ return '中文 (繁體)';
+ default:
+ return '中文';
+ }
+ default:
+ return locale.languageCode;
+ }
+ }
+
+ Widget _menuItemForPicker(Locale locale) {
+ return MenuItemWidget(
+ key: ValueKey(locale.toString()),
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ captionedTextWidget: CaptionedTextWidget(
+ title: _getLanguageName(locale) + (kDebugMode ? ' ($locale)' : ''),
+ ),
+ trailingIcon: currentLocale == locale ? Icons.check : null,
+ alignCaptionedTextToLeft: true,
+ isTopBorderRadiusRemoved: true,
+ isBottomBorderRadiusRemoved: true,
+ showOnlyLoadingState: true,
+ onTap: () async {
+ widget.onLocaleChanged(locale);
+ currentLocale = locale;
+ setState(() {});
+ },
+ );
+ }
+}