Skip to content

Commit

Permalink
issue-130 make localization independent from context
Browse files Browse the repository at this point in the history
  • Loading branch information
gennadyterekhov committed Jun 9, 2024
1 parent 9b66110 commit 3662942
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 181 deletions.
13 changes: 5 additions & 8 deletions lib/layers/data/resources/custom_localization.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import 'package:flutter/widgets.dart';
import 'package:the_elder_scrolls_alchemy_client/app.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/main.dart';

class CustomLocalization {
static getEffectName({
required String gameName,
required String englishEffectName,
required BuildContext context,
required String languageCode,
}) {
String? localizedEffectName =
DataResource.getLocalizedMap()[gameName]!['effects']?[englishEffectName]?[TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)];
DataResource.getLocalizedMap()[gameName]!['effects']?[englishEffectName]?[languageCode];

return ((localizedEffectName != null) && (localizedEffectName != '')) ? localizedEffectName : englishEffectName;
}

static getIngredientName({
required String gameName,
required String englishIngredientName,
required BuildContext context,
required String languageCode,
}) {
String? localizedIngredientName = DataResource.getLocalizedMap()[gameName]!['ingredients']?[englishIngredientName]
?[TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)];
String? localizedIngredientName =
DataResource.getLocalizedMap()[gameName]!['ingredients']?[englishIngredientName]?[languageCode];

return ((localizedIngredientName != null) && (localizedIngredientName != ''))
? localizedIngredientName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/state_management/app_state.dart';
import 'package:the_elder_scrolls_alchemy_client/main.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart';
import 'package:the_elder_scrolls_alchemy_client/router.dart';

import '../../../../../../app.dart';

class EffectCardMicro extends StatefulWidget {
const EffectCardMicro({Key? key, required this.gameName, required this.effect, this.fontSize = 30.0})
Expand All @@ -28,7 +26,9 @@ class _EffectCardMicroState extends State<EffectCardMicro> {
@override
Widget build(BuildContext context) {
final label = CustomLocalization.getEffectName(
gameName: widget.gameName, englishEffectName: widget.effect.name, context: context);
gameName: widget.gameName,
englishEffectName: widget.effect.name,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context));

final effectColor = widget.effect.type == 'positive'
? Constant.positiveEffectBackgroundColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart';

import '../../../../../app.dart';

class EffectNameText extends StatelessWidget {
const EffectNameText({Key? key, required this.gameName, required this.effect}) : super(key: key);
final Effect effect;
Expand All @@ -10,7 +12,10 @@ class EffectNameText extends StatelessWidget {
@override
Widget build(BuildContext context) {
final nameText = SelectableText(
CustomLocalization.getEffectName(gameName: gameName, englishEffectName: effect.name, context: context),
CustomLocalization.getEffectName(
gameName: gameName,
englishEffectName: effect.name,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)),
textAlign: TextAlign.left,
style: const TextStyle(
fontWeight: FontWeight.bold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ef
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart';

import '../../../../../app.dart';

class EffectSmallImage extends StatelessWidget {
const EffectSmallImage({Key? key, required this.gameName, required this.effect}) : super(key: key);
final Effect effect;
Expand All @@ -11,7 +13,10 @@ class EffectSmallImage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Text nameText = Text(
CustomLocalization.getEffectName(gameName: this.gameName, englishEffectName: this.effect.name, context: context),
CustomLocalization.getEffectName(
gameName: this.gameName,
englishEffectName: this.effect.name,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)),
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: const TextStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/com
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/divider_text.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/lists/effects_by_ingredient.dart';

import '../../../../../../app.dart';

class IngredientCardLong extends StatefulWidget {
const IngredientCardLong({Key? key, required this.gameName, required this.ingredient}) : super(key: key);
final Ingredient ingredient;
Expand All @@ -20,7 +22,9 @@ class _IngredientCardLongState extends State<IngredientCardLong> {
Widget build(BuildContext context) {
SelectableText nameText = SelectableText(
CustomLocalization.getIngredientName(
gameName: widget.gameName, englishIngredientName: widget.ingredient.name, context: context),
gameName: widget.gameName,
englishIngredientName: widget.ingredient.name,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)),
textAlign: TextAlign.left,
style: const TextStyle(
overflow: TextOverflow.fade,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/state_management/app_state.dart';
import 'package:the_elder_scrolls_alchemy_client/main.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart';
import 'package:the_elder_scrolls_alchemy_client/router.dart';

import '../../../../../../app.dart';

class IngredientCardMicro extends StatefulWidget {
const IngredientCardMicro({Key? key, required this.gameName, required this.ingredient}) : super(key: key);
Expand All @@ -26,7 +24,9 @@ class _IngredientCardMicroState extends State<IngredientCardMicro> {
@override
Widget build(BuildContext context) {
final label = CustomLocalization.getIngredientName(
gameName: widget.gameName, englishIngredientName: widget.ingredient.name, context: context);
gameName: widget.gameName,
englishIngredientName: widget.ingredient.name,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context));
final fontSize = 20.0;

final text = Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/state_management/app_state.dart';
import 'package:the_elder_scrolls_alchemy_client/main.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart';
import 'package:the_elder_scrolls_alchemy_client/router.dart';

import '../../../../../../app.dart';

class IngredientCardSmall extends StatefulWidget {
const IngredientCardSmall({Key? key, required this.gameName, required this.ingredient}) : super(key: key);
Expand All @@ -27,7 +25,9 @@ class _IngredientCardSmallState extends State<IngredientCardSmall> {
margin: const EdgeInsets.only(top: 8.0),
child: Text(
CustomLocalization.getIngredientName(
gameName: widget.gameName, englishIngredientName: widget.ingredient.name, context: context),
gameName: widget.gameName,
englishIngredientName: widget.ingredient.name,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)),
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: const TextStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/effect_re
import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/ingredient_resource.dart';
import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_micro.dart';

import '../../../../../app.dart';

class CommonIngredientsByColumn extends StatefulWidget {
const CommonIngredientsByColumn({Key? key, required this.gameName, required this.ingredient}) : super(key: key);
final Ingredient ingredient;
Expand Down Expand Up @@ -79,7 +81,7 @@ class _CommonIngredientsByColumnState extends State<CommonIngredientsByColumn> {
CustomLocalization.getEffectName(
gameName: widget.gameName,
englishEffectName: widget.ingredient.effectsNames[i],
context: context,
languageCode: TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context),
),
style: TextStyle(color: Colors.grey),
),
Expand Down
2 changes: 1 addition & 1 deletion macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import FlutterMacOS
import Foundation

import path_provider_macos
import path_provider_foundation
import shared_preferences_foundation
import url_launcher_macos

Expand Down
Loading

0 comments on commit 3662942

Please sign in to comment.