-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/translations #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andriikamaldinov1
wants to merge
5
commits into
develop
Choose a base branch
from
feat/translations
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7eef202
feat(ref: no-ref): add translations
andriikamaldinov1 a2866af
feat(ref: no-ref): add translations
andriikamaldinov1 58e9afd
feat(ref: no-ref): add translations
andriikamaldinov1 b6fb185
feat(ref: no-ref): fix comments
andriikamaldinov1 9de1c4b
feat(ref: no-ref): fix comments
andriikamaldinov1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import '../../screens/home/title/title.translation.dart' as home_title; | ||
import '../../screens/home/todo/add-task/add-task.translation.dart' | ||
as home_add_task; | ||
import '../../screens/home/todo/filter-panel/filter-panel.translation.dart' | ||
as home_filter_panel; | ||
import '../remaining-items/remaining-items.translation.dart' as remaining_items; | ||
|
||
class AppTranslation extends GetxService { | ||
AppTranslation(); | ||
|
||
Map<String, Map<String, String>> translationsKeys = | ||
<String, Map<String, String>>{ | ||
'en': en, | ||
'uk': uk, | ||
'ru': ru, | ||
}; | ||
|
||
void _combineTranslations(Map<String, String> enTranslations, | ||
Map<String, String> ukTranslations, Map<String, String> ruTranslations) { | ||
translationsKeys['en']!.addAll(enTranslations); | ||
translationsKeys['uk']!.addAll(ukTranslations); | ||
translationsKeys['ru']!.addAll(ruTranslations); | ||
} | ||
|
||
Map<String, Map<String, String>> combineAllTranslations() { | ||
_combineTranslations( | ||
home_title.en, | ||
home_title.uk, | ||
home_title.ru, | ||
); | ||
|
||
_combineTranslations( | ||
home_add_task.en, | ||
home_add_task.uk, | ||
home_add_task.ru, | ||
); | ||
|
||
_combineTranslations( | ||
home_filter_panel.en, | ||
home_filter_panel.uk, | ||
home_filter_panel.ru, | ||
); | ||
|
||
_combineTranslations( | ||
remaining_items.en, | ||
remaining_items.uk, | ||
remaining_items.ru, | ||
); | ||
|
||
andriikamaldinov1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return translationsKeys; | ||
} | ||
} | ||
|
||
final Map<String, String> en = <String, String>{}; | ||
final Map<String, String> uk = <String, String>{}; | ||
final Map<String, String> ru = <String, String>{}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:get/get.dart'; | ||
|
||
abstract class Translation {} | ||
|
||
extension Translations on Translation { | ||
String get st => '$this'; | ||
String get tr => st.tr; | ||
} | ||
|
||
extension MapEnumExtensions on Map<Translation, String> { | ||
Map<String, String> get st => Map<String, String>.fromEntries(entries.map( | ||
(MapEntry<Translation, String> entry) => | ||
MapEntry<String, String>(entry.key.st, entry.value))); | ||
} |
30 changes: 30 additions & 0 deletions
30
lib/common/remaining-items/remaining-items.extensions.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:intl/intl.dart'; | ||
|
||
import '../app-translation/translation.extensions.dart'; | ||
import 'remaining-items.translation.dart'; | ||
|
||
extension RemainingItemsFormatter on int { | ||
String get remainingItemsText => _getPlural( | ||
this, | ||
one: RemainingItemsTranslationNames.oneItem.tr, | ||
few: RemainingItemsTranslationNames.fewItems.tr, | ||
many: RemainingItemsTranslationNames.manyItems.tr, | ||
).trim(); | ||
|
||
String _getPlural(int value, | ||
{required String one, required String few, required String many}) { | ||
if (value > 0) { | ||
return Intl.plural( | ||
value, | ||
zero: '', | ||
one: '$value $one', | ||
few: '$value $few', | ||
many: '$value $many', | ||
other: '$value $many', | ||
locale: Get.locale?.languageCode, | ||
); | ||
} | ||
return ''; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/common/remaining-items/remaining-items.translation.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import '../../../../common/app-translation/translation.extensions.dart'; | ||
|
||
enum RemainingItemsTranslationNames implements Translation { | ||
oneItem, | ||
fewItems, | ||
manyItems, | ||
} | ||
|
||
final Map<String, String> en = <RemainingItemsTranslationNames, String>{ | ||
RemainingItemsTranslationNames.oneItem: 'item left', | ||
RemainingItemsTranslationNames.fewItems: 'items left', | ||
RemainingItemsTranslationNames.manyItems: 'items left', | ||
}.st; | ||
|
||
final Map<String, String> ru = <RemainingItemsTranslationNames, String>{ | ||
RemainingItemsTranslationNames.oneItem: 'элемент остался', | ||
RemainingItemsTranslationNames.fewItems: 'элемента осталось', | ||
RemainingItemsTranslationNames.manyItems: 'элементов осталось', | ||
}.st; | ||
|
||
final Map<String, String> uk = <RemainingItemsTranslationNames, String>{ | ||
RemainingItemsTranslationNames.oneItem: 'елемент залишився', | ||
RemainingItemsTranslationNames.fewItems: 'елементи залишились', | ||
RemainingItemsTranslationNames.manyItems: 'елементів залишилось', | ||
}.st; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
lib/screens/home/language-switcher/language-switcher.controller.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:get/get.dart'; | ||
import 'language-switcher.enum.dart'; | ||
|
||
class LanguageSwitcherController extends GetxController { | ||
final Rx<Language> currentLanguage = Language.en.obs; | ||
|
||
void updateLocale(Language language) { | ||
currentLanguage.value = language; | ||
Get.updateLocale(language.locale); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
lib/screens/home/language-switcher/language-switcher.enum.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'dart:ui'; | ||
|
||
enum Language { | ||
en(Locale('en'), 'English'), | ||
ru(Locale('ru'), 'Русский'), | ||
uk(Locale('uk'), 'Українська'); | ||
|
||
const Language(this.locale, this.title); | ||
|
||
final Locale locale; | ||
final String title; | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/screens/home/language-switcher/language-switcher.widget.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'language-switcher.controller.dart'; | ||
import 'language-switcher.enum.dart'; | ||
|
||
class LanguageSwitcherWidget extends GetView<LanguageSwitcherController> { | ||
const LanguageSwitcherWidget({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) => Obx(() => DropdownButton<Language>( | ||
value: controller.currentLanguage.value, | ||
onChanged: (Language? language) { | ||
if (language != null) { | ||
controller.updateLocale(language); | ||
} | ||
}, | ||
items: Language.values | ||
.map<DropdownMenuItem<Language>>( | ||
(Language language) => DropdownMenuItem<Language>( | ||
value: language, | ||
child: Text(language.title), | ||
)) | ||
.toList(), | ||
)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import '../../../common/app-translation/translation.extensions.dart'; | ||
|
||
enum TitleTranslationNames implements Translation { | ||
title, | ||
} | ||
|
||
final Map<String, String> en = <TitleTranslationNames, String>{ | ||
TitleTranslationNames.title: 'todos', | ||
}.st; | ||
|
||
final Map<String, String> ru = <TitleTranslationNames, String>{ | ||
TitleTranslationNames.title: 'Список задач', | ||
}.st; | ||
|
||
final Map<String, String> uk = <TitleTranslationNames, String>{ | ||
TitleTranslationNames.title: 'Список завдань', | ||
}.st; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import '../../../../common/app-translation/translation.extensions.dart'; | ||
|
||
enum AddTaskTranslationNames implements Translation { | ||
title, | ||
} | ||
|
||
final Map<String, String> en = <AddTaskTranslationNames, String>{ | ||
AddTaskTranslationNames.title: 'What needs to be done?', | ||
}.st; | ||
|
||
final Map<String, String> ru = <AddTaskTranslationNames, String>{ | ||
AddTaskTranslationNames.title: 'Что нужно сделать?', | ||
}.st; | ||
|
||
final Map<String, String> uk = <AddTaskTranslationNames, String>{ | ||
AddTaskTranslationNames.title: 'Що потрібно зробити?', | ||
}.st; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import '../../../../common/app-translation/translation.extensions.dart'; | ||
import 'filter-panel.translation.dart'; | ||
|
||
enum FilterType { | ||
all('All'), | ||
active('Active'), | ||
completed('Completed'); | ||
all(FilterPanelTranslationNames.all), | ||
active(FilterPanelTranslationNames.active), | ||
completed(FilterPanelTranslationNames.completed); | ||
|
||
const FilterType(this.translationKey); | ||
|
||
const FilterType(this.type); | ||
final FilterPanelTranslationNames translationKey; | ||
|
||
final String type; | ||
String get type => translationKey.tr; | ||
} |
29 changes: 29 additions & 0 deletions
29
lib/screens/home/todo/filter-panel/filter-panel.translation.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import '../../../../common/app-translation/translation.extensions.dart'; | ||
|
||
enum FilterPanelTranslationNames implements Translation { | ||
clearItems, | ||
all, | ||
active, | ||
completed | ||
} | ||
|
||
final Map<String, String> en = <FilterPanelTranslationNames, String>{ | ||
FilterPanelTranslationNames.clearItems: 'Clear completed', | ||
FilterPanelTranslationNames.all: 'All', | ||
FilterPanelTranslationNames.active: 'Active', | ||
FilterPanelTranslationNames.completed: 'Completed', | ||
}.st; | ||
|
||
final Map<String, String> ru = <FilterPanelTranslationNames, String>{ | ||
FilterPanelTranslationNames.clearItems: 'Очистить выполненные', | ||
FilterPanelTranslationNames.all: 'Все', | ||
FilterPanelTranslationNames.active: 'Активные', | ||
FilterPanelTranslationNames.completed: 'Выполненные', | ||
}.st; | ||
|
||
final Map<String, String> uk = <FilterPanelTranslationNames, String>{ | ||
FilterPanelTranslationNames.clearItems: 'Очистити виконані', | ||
FilterPanelTranslationNames.all: 'Усі', | ||
FilterPanelTranslationNames.active: 'Активні', | ||
FilterPanelTranslationNames.completed: 'Виконані', | ||
}.st; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.