mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 06:39:25 +01:00
feat: Implement official emoji translations for emoji verification
This commit is contained in:
parent
7b31c00d53
commit
95bcb467c7
@ -177,3 +177,5 @@ location /_matrix/push/v1/notify {
|
|||||||
* Also thanks to all translators and testers! With your help, fluffychat is now available in more than 12 languages.
|
* Also thanks to all translators and testers! With your help, fluffychat is now available in more than 12 languages.
|
||||||
|
|
||||||
* <a href="https://github.com/googlefonts/noto-emoji/">Noto Emoji Font</a> for the awesome emojis.
|
* <a href="https://github.com/googlefonts/noto-emoji/">Noto Emoji Font</a> for the awesome emojis.
|
||||||
|
|
||||||
|
* The Matrix Foundation for making and maintaining the [emoji translations](https://github.com/matrix-org/matrix-doc/blob/master/data-definitions/sas-emoji.json) used for emoji verification, licensed Apache 2.0
|
||||||
|
2178
assets/sas-emoji.json
Normal file
2178
assets/sas-emoji.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,13 @@
|
|||||||
|
import 'dart:ui';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:matrix/encryption.dart';
|
import 'package:matrix/encryption.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import '../widgets/adaptive_flat_button.dart';
|
import '../widgets/adaptive_flat_button.dart';
|
||||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
@ -37,6 +41,7 @@ class KeyVerificationDialog extends StatefulWidget {
|
|||||||
|
|
||||||
class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
||||||
void Function() originalOnUpdate;
|
void Function() originalOnUpdate;
|
||||||
|
List<dynamic> sasEmoji;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -51,6 +56,10 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||||||
profile = p;
|
profile = p;
|
||||||
setState(() => null);
|
setState(() => null);
|
||||||
});
|
});
|
||||||
|
rootBundle.loadString('assets/sas-emoji.json').then((e) {
|
||||||
|
sasEmoji = json.decode(e);
|
||||||
|
setState(() => null);
|
||||||
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +217,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||||||
compareText = L10n.of(context).compareEmojiMatch;
|
compareText = L10n.of(context).compareEmojiMatch;
|
||||||
compareWidget = TextSpan(
|
compareWidget = TextSpan(
|
||||||
children: widget.request.sasEmojis
|
children: widget.request.sasEmojis
|
||||||
.map((e) => WidgetSpan(child: _Emoji(e)))
|
.map((e) => WidgetSpan(child: _Emoji(e, sasEmoji)))
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -371,8 +380,33 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||||||
|
|
||||||
class _Emoji extends StatelessWidget {
|
class _Emoji extends StatelessWidget {
|
||||||
final KeyVerificationEmoji emoji;
|
final KeyVerificationEmoji emoji;
|
||||||
|
final List<dynamic> sasEmoji;
|
||||||
|
|
||||||
_Emoji(this.emoji);
|
_Emoji(this.emoji, this.sasEmoji);
|
||||||
|
|
||||||
|
String getLocalizedName() {
|
||||||
|
if (sasEmoji == null) {
|
||||||
|
// asset is still being loaded
|
||||||
|
return emoji.name;
|
||||||
|
}
|
||||||
|
final translations = Map<String, String>.from(
|
||||||
|
sasEmoji[emoji.number]['translated_descriptions']);
|
||||||
|
translations['en'] = emoji.name;
|
||||||
|
for (final locale in window.locales) {
|
||||||
|
final wantLocaleParts = locale.toString().split('_');
|
||||||
|
final wantLanguage = wantLocaleParts.removeAt(0);
|
||||||
|
for (final haveLocale in translations.keys) {
|
||||||
|
final haveLocaleParts = haveLocale.split('_');
|
||||||
|
final haveLanguage = haveLocaleParts.removeAt(0);
|
||||||
|
if (haveLanguage == wantLanguage &&
|
||||||
|
(Set.from(haveLocaleParts)..removeAll(wantLocaleParts)).isEmpty &&
|
||||||
|
(translations[haveLocale]?.isNotEmpty ?? false)) {
|
||||||
|
return translations[haveLocale];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emoji.name;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -380,7 +414,7 @@ class _Emoji extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(emoji.emoji, style: TextStyle(fontSize: 50)),
|
Text(emoji.emoji, style: TextStyle(fontSize: 50)),
|
||||||
Text(emoji.name),
|
Text(getLocalizedName()),
|
||||||
Container(height: 10, width: 5),
|
Container(height: 10, width: 5),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user