[PR #2299] [MERGED] [EC-1002] [BEEEP] Add ability to change language in app #3493

Closed
opened 2025-11-26 23:33:31 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/bitwarden/android/pull/2299
Author: @fedemkr
Created: 1/16/2023
Status: Merged
Merged: 3/1/2023
Merged by: @fedemkr

Base: masterHead: EC-1002-change-language-in-app


📝 Commits (6)

  • 496f68c EC-1002 BEEEP Added ability to change language in app
  • 312b951 Merge branch 'master' into EC-1002-change-language-in-app
  • 1258b96 EC-1002 fix format
  • 1abea91 Merge branch 'master' into EC-1002-change-language-in-app
  • 846ad9a EC-1002 Renamed IPreferencesStorageService to ISynchronousStorageService
  • 2419573 EC-1002 Moved get/set Locale to the StateService and added the StorageMediatorService to a new way to interact with the storage. Later the StateService will only interact with this mediator instead of directly with the storage services, with this we have more control inside the mediator and we can have both sync and async methods to interact with storages handled by the mediator

📊 Changes

18 files changed (+298 additions, -29 deletions)

View changed files

📝 src/Android/MainApplication.cs (+7 -2)
📝 src/Android/Properties/AndroidManifest.xml (+2 -2)
📝 src/App/Pages/Settings/OptionsPage.xaml (+16 -0)
📝 src/App/Pages/Settings/OptionsPage.xaml.cs (+1 -0)
📝 src/App/Pages/Settings/OptionsPageViewModel.cs (+47 -1)
📝 src/App/Resources/AppResources.Designer.cs (+36 -0)
📝 src/App/Resources/AppResources.resx (+12 -0)
📝 src/App/Services/MobileI18nService.cs (+13 -7)
📝 src/App/Services/PreferencesStorageService.cs (+28 -15)
📝 src/Core/Abstractions/II18nService.cs (+1 -0)
📝 src/Core/Abstractions/IStateService.cs (+3 -0)
src/Core/Abstractions/IStorageMediatorService.cs (+16 -0)
src/Core/Abstractions/ISynchronousStorageService.cs (+9 -0)
📝 src/Core/Constants.cs (+1 -0)
📝 src/Core/Services/StateService.cs (+29 -0)
src/Core/Services/StorageMediatorOptions.cs (+8 -0)
src/Core/Services/StorageMediatorService.cs (+62 -0)
📝 src/iOS.Core/Utilities/iOSCoreHelpers.cs (+7 -2)

📄 Description

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Add ability to change the language from the app. For now it requires app restart to apply the change.

Code changes

  • OptionsPage.xaml: Added language picker
  • OptionsPageViewModel: Added possibility to select a language/locale, also added system option (with null key value). This is saved into preferences.
  • MainApplication, iOSCoreHelpers: Load the app locale if any selected and set the app culture.
  • MobileI18NService: Added SetCulture(...) so that the culture can be from away the class and fixed some caps in the languages (IDK if the others should be in caps or not)
  • IPreferencesStorageService, PreferencesStorageService: Added sync methods for Get, Save, Remove and the interface so the caller can use the synchronous way instead of the async one of the IStorageService. This was done to avoid needing async code for setting the culture when the app is loading which caused some race conditions and therefore some strings weren't translated correctly because the strings were being translated before the Culture was actually updated.
  • StorageMediatorService: Added this mediator in order to interact with the storages. With this we can have sync and async methods of interaction where the logic to choose one or the other is transparent to the caller and there are also StorageMediatorOptions to pass.
  • StateService: Added get/set Locale to here to be alike to other global settings like theming. Additionally, now it uses the aforementioned mediator to interact with the storages. For now, it's only applied to Locale but afterwards it'll be refactored so that the storage services are removed from here and the mediator is used for everything. Also, marked some methods as Obsolete so the mediator is used in new additional features.
  • Others: Use the StateService to get/set the locale

Screenshots

Language option Language option selector Language selected message Language option dark theme

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/bitwarden/android/pull/2299 **Author:** [@fedemkr](https://github.com/fedemkr) **Created:** 1/16/2023 **Status:** ✅ Merged **Merged:** 3/1/2023 **Merged by:** [@fedemkr](https://github.com/fedemkr) **Base:** `master` ← **Head:** `EC-1002-change-language-in-app` --- ### 📝 Commits (6) - [`496f68c`](https://github.com/bitwarden/android/commit/496f68cba648f306250338917254e883f02fb675) EC-1002 BEEEP Added ability to change language in app - [`312b951`](https://github.com/bitwarden/android/commit/312b95135c66b497f48dc0ea6a110c84f3d309dd) Merge branch 'master' into EC-1002-change-language-in-app - [`1258b96`](https://github.com/bitwarden/android/commit/1258b96130523f936fbcefb9d75167aa97eea5d0) EC-1002 fix format - [`1abea91`](https://github.com/bitwarden/android/commit/1abea9168874391c2d1998b20cca165b76176edd) Merge branch 'master' into EC-1002-change-language-in-app - [`846ad9a`](https://github.com/bitwarden/android/commit/846ad9affcdc85e9250a36b781a5e38ec2c32862) EC-1002 Renamed IPreferencesStorageService to ISynchronousStorageService - [`2419573`](https://github.com/bitwarden/android/commit/2419573c89f05b14a9e28b62a9c7d80696f9c017) EC-1002 Moved get/set Locale to the StateService and added the StorageMediatorService to a new way to interact with the storage. Later the StateService will only interact with this mediator instead of directly with the storage services, with this we have more control inside the mediator and we can have both sync and async methods to interact with storages handled by the mediator ### 📊 Changes **18 files changed** (+298 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src/Android/MainApplication.cs` (+7 -2) 📝 `src/Android/Properties/AndroidManifest.xml` (+2 -2) 📝 `src/App/Pages/Settings/OptionsPage.xaml` (+16 -0) 📝 `src/App/Pages/Settings/OptionsPage.xaml.cs` (+1 -0) 📝 `src/App/Pages/Settings/OptionsPageViewModel.cs` (+47 -1) 📝 `src/App/Resources/AppResources.Designer.cs` (+36 -0) 📝 `src/App/Resources/AppResources.resx` (+12 -0) 📝 `src/App/Services/MobileI18nService.cs` (+13 -7) 📝 `src/App/Services/PreferencesStorageService.cs` (+28 -15) 📝 `src/Core/Abstractions/II18nService.cs` (+1 -0) 📝 `src/Core/Abstractions/IStateService.cs` (+3 -0) ➕ `src/Core/Abstractions/IStorageMediatorService.cs` (+16 -0) ➕ `src/Core/Abstractions/ISynchronousStorageService.cs` (+9 -0) 📝 `src/Core/Constants.cs` (+1 -0) 📝 `src/Core/Services/StateService.cs` (+29 -0) ➕ `src/Core/Services/StorageMediatorOptions.cs` (+8 -0) ➕ `src/Core/Services/StorageMediatorService.cs` (+62 -0) 📝 `src/iOS.Core/Utilities/iOSCoreHelpers.cs` (+7 -2) </details> ### 📄 Description ## Type of change - [ ] Bug fix - [X] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ## Objective <!--Describe what the purpose of this PR is. For example: what bug you're fixing or what new feature you're adding--> Add ability to change the language from the app. For now it requires app restart to apply the change. ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> * **OptionsPage.xaml:** Added language picker * **OptionsPageViewModel:** Added possibility to select a language/locale, also added system option (with null key value). This is saved into preferences. * **MainApplication, iOSCoreHelpers:** Load the app locale if any selected and set the app culture. * **MobileI18NService:** Added `SetCulture(...)` so that the culture can be from away the class and fixed some caps in the languages (IDK if the others should be in caps or not) * **IPreferencesStorageService, PreferencesStorageService:** Added sync methods for Get, Save, Remove and the interface so the caller can use the synchronous way instead of the async one of the `IStorageService`. This was done to avoid needing async code for setting the culture when the app is loading which caused some race conditions and therefore some strings weren't translated correctly because the strings were being translated before the Culture was actually updated. * **StorageMediatorService:** Added this mediator in order to interact with the storages. With this we can have sync and async methods of interaction where the logic to choose one or the other is transparent to the caller and there are also `StorageMediatorOptions` to pass. * **StateService:** Added get/set `Locale` to here to be alike to other global settings like theming. Additionally, now it uses the aforementioned mediator to interact with the storages. For now, it's only applied to `Locale` but afterwards it'll be refactored so that the storage services are removed from here and the mediator is used for everything. Also, marked some methods as `Obsolete` so the mediator is used in new additional features. * **Others:** Use the `StateService` to get/set the locale ## Screenshots <!--Required for any UI changes. Delete if not applicable--> <img width="314" alt="Language option" src="https://user-images.githubusercontent.com/15682323/212739118-e96ddd0c-d1da-4f00-92f2-8e7fa36cdc1b.jpeg"> <img width="314" alt="Language option selector" src="https://user-images.githubusercontent.com/15682323/212739110-0b58081a-c643-47d3-ab6d-360fd9b47903.jpeg"> <img width="314" alt="Language selected message" src="https://user-images.githubusercontent.com/15682323/212739104-1677cfa7-0505-41ec-b41f-7530fd31be99.jpeg"> <img width="314" alt="Language option dark theme" src="https://user-images.githubusercontent.com/15682323/212739091-f0920c3b-8c61-44ca-a761-1e2815379050.jpeg"> ## Before you submit - Please check for formatting errors (`dotnet format --verify-no-changes`) (required) - Please add **unit tests** where it makes sense to do so (encouraged but not required) - If this change requires a **documentation update** - notify the documentation team - If this change has particular **deployment requirements** - notify the DevOps team --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-26 23:33:31 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/android#3493