You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import 'dart:convert';
import 'package:data/app_setting_data/repository/app_setting_box_repository_impl.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show rootBundle; import 'package:local_db_core/lib/boxes/box_list/setting_box/app_setting_box.dart'; import 'package:repositories/app_setting_box_domain/repository/app_setting_box_repository.dart'; import 'package:sonnat/core/language/languages.dart';
final List<String> supportedLanguages = [ 'en', 'fa', 'ar', ];
class Translator { static Map<dynamic, dynamic>? _localizedValues;
static Iterable<Locale> supportedLocales() => supportedLanguages.map<Locale>((lang) => Locale(lang, ''));
static String translate(String key) { if (_localizedValues == null || _localizedValues![key] == null) { return '$key not found'; } return _localizedValues![key]; }
static Future<void> setNewLanguage(Languages newLanguage) async { AppSettingBoxRepository repository = AppSettingBoxRepositoryImpl(appSettingBox: AppSettingBox()); Locale locale = Locale(newLanguage.value, ''); String jsonContent = await rootBundle.loadString('assets/languages/${locale.languageCode}.json'); _localizedValues = json.decode(jsonContent); await repository.setCurrentLanguage(locale.languageCode); return; }
Translator._internal(); }
|