// Label StoreMAX // // Created by Anthony Gordon. // Copyright © 2020 WooSignal. All rights reserved. // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import 'dart:async'; import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import '../labelconfig.dart'; class AppLocalizations { final Locale locale; AppLocalizations(this.locale); static AppLocalizations of(BuildContext context) { return Localizations.of(context, AppLocalizations); } static const LocalizationsDelegate delegate = _AppLocalizationsDelegate(); Map _localizedStrings; Future load() async { String jsonString = await rootBundle.loadString('lang/${locale.languageCode}.json'); Map jsonMap = json.decode(jsonString); _localizedStrings = jsonMap.map((k, v) { return MapEntry(k, v.toString()); }); } String trans(String key) { return _localizedStrings[key]; } } class _AppLocalizationsDelegate extends LocalizationsDelegate { const _AppLocalizationsDelegate(); @override bool isSupported(Locale locale) => app_locales_supported.contains(locale.languageCode); @override bool shouldReload(_AppLocalizationsDelegate old) => false; Future load(Locale locale) async { AppLocalizations localizations = new AppLocalizations(locale); await localizations.load(); return localizations; } }