You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
import 'dart:convert';
 | 
						|
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
import 'package:flutter/services.dart';
 | 
						|
import 'package:test_sa/models/subtitle.dart';
 | 
						|
 | 
						|
class AppLocalization {
 | 
						|
  AppLocalization(this.locale);
 | 
						|
 | 
						|
  final Locale locale;
 | 
						|
  static AppLocalization of(BuildContext context) {
 | 
						|
    return Localizations.of<AppLocalization>(context, AppLocalization);
 | 
						|
  }
 | 
						|
 | 
						|
  Subtitle _subtitle;
 | 
						|
  Subtitle get subtitle => _subtitle;
 | 
						|
 | 
						|
  Future<void> load() async {
 | 
						|
    String jsonStringValues = await rootBundle.loadString('assets/subtitles/${locale.languageCode}_subtitle.json');
 | 
						|
    _subtitle = Subtitle.fromJson(json.decode(jsonStringValues));
 | 
						|
  }
 | 
						|
 | 
						|
  // static member to have simple access to the delegate from Material App
 | 
						|
  static const LocalizationsDelegate<AppLocalization> delegate = _DemoLocalizationsDelegate();
 | 
						|
}
 | 
						|
 | 
						|
class _DemoLocalizationsDelegate extends LocalizationsDelegate<AppLocalization> {
 | 
						|
  const _DemoLocalizationsDelegate();
 | 
						|
 | 
						|
  @override
 | 
						|
  bool isSupported(Locale locale) {
 | 
						|
    return ['en', 'ar'].contains(locale.languageCode);
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  Future<AppLocalization> load(Locale locale) async {
 | 
						|
    AppLocalization localization = new AppLocalization(locale);
 | 
						|
    await localization.load();
 | 
						|
    return localization;
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  bool shouldReload(LocalizationsDelegate<AppLocalization> old) => false;
 | 
						|
}
 |