|
|
|
@ -1,21 +1,26 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:fluffychat/l10n/l10n.dart';
|
|
|
|
import 'package:fluffychat/l10n/l10n.dart';
|
|
|
|
import 'package:fluffychat/pangea/learning_settings/constants/language_constants.dart';
|
|
|
|
import 'package:fluffychat/pangea/learning_settings/constants/language_constants.dart';
|
|
|
|
import 'package:fluffychat/pangea/learning_settings/enums/l2_support_enum.dart';
|
|
|
|
import 'package:fluffychat/pangea/learning_settings/enums/l2_support_enum.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/pangea/learning_settings/utils/p_language_store.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class LanguageModel {
|
|
|
|
class LanguageModel {
|
|
|
|
final String langCode;
|
|
|
|
final String langCode;
|
|
|
|
final String displayName;
|
|
|
|
final String displayName;
|
|
|
|
final String script;
|
|
|
|
final String script;
|
|
|
|
final L2SupportEnum l2Support;
|
|
|
|
final L2SupportEnum l2Support;
|
|
|
|
|
|
|
|
final TextDirection? _textDirection;
|
|
|
|
|
|
|
|
|
|
|
|
LanguageModel({
|
|
|
|
LanguageModel({
|
|
|
|
required this.langCode,
|
|
|
|
required this.langCode,
|
|
|
|
required this.displayName,
|
|
|
|
required this.displayName,
|
|
|
|
this.script = LanguageKeys.unknownLanguage,
|
|
|
|
this.script = LanguageKeys.unknownLanguage,
|
|
|
|
this.l2Support = L2SupportEnum.na,
|
|
|
|
this.l2Support = L2SupportEnum.na,
|
|
|
|
});
|
|
|
|
TextDirection? textDirection,
|
|
|
|
|
|
|
|
}) : _textDirection = textDirection;
|
|
|
|
|
|
|
|
|
|
|
|
factory LanguageModel.fromJson(json) {
|
|
|
|
factory LanguageModel.fromJson(json) {
|
|
|
|
final String code = json['language_code'] ??
|
|
|
|
final String code = json['language_code'] ??
|
|
|
|
@ -31,6 +36,11 @@ class LanguageModel {
|
|
|
|
? L2SupportEnum.na.fromStorageString(json['l2_support'])
|
|
|
|
? L2SupportEnum.na.fromStorageString(json['l2_support'])
|
|
|
|
: L2SupportEnum.na,
|
|
|
|
: L2SupportEnum.na,
|
|
|
|
script: json['script'] ?? LanguageKeys.unknownLanguage,
|
|
|
|
script: json['script'] ?? LanguageKeys.unknownLanguage,
|
|
|
|
|
|
|
|
textDirection: json['text_direction'] != null
|
|
|
|
|
|
|
|
? TextDirection.values.firstWhereOrNull(
|
|
|
|
|
|
|
|
(e) => e.name == json['text_direction'],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
: null,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -39,6 +49,7 @@ class LanguageModel {
|
|
|
|
'language_name': displayName,
|
|
|
|
'language_name': displayName,
|
|
|
|
'script': script,
|
|
|
|
'script': script,
|
|
|
|
'l2_support': l2Support.storageString,
|
|
|
|
'l2_support': l2Support.storageString,
|
|
|
|
|
|
|
|
'text_direction': textDirection.name,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool get l2 => l2Support != L2SupportEnum.na;
|
|
|
|
bool get l2 => l2Support != L2SupportEnum.na;
|
|
|
|
@ -73,6 +84,16 @@ class LanguageModel {
|
|
|
|
|
|
|
|
|
|
|
|
String get langCodeShort => langCode.split('-').first;
|
|
|
|
String get langCodeShort => langCode.split('-').first;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextDirection get _defaultTextDirection {
|
|
|
|
|
|
|
|
return PLanguageStore.rtlLanguageCodes.contains(langCodeShort)
|
|
|
|
|
|
|
|
? TextDirection.rtl
|
|
|
|
|
|
|
|
: TextDirection.ltr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextDirection get textDirection {
|
|
|
|
|
|
|
|
return _textDirection ?? _defaultTextDirection;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
if (other is LanguageModel) {
|
|
|
|
if (other is LanguageModel) {
|
|
|
|
|