diff --git a/lib/project/project_page.dart b/lib/project/project_page.dart index a0dff04..0b31596 100644 --- a/lib/project/project_page.dart +++ b/lib/project/project_page.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; + +import 'package:archive/archive_io.dart'; import 'package:doppio_dev_ixn/core/index.dart'; import 'package:doppio_dev_ixn/main.dart'; import 'package:doppio_dev_ixn/project_setting/index.dart'; @@ -7,6 +10,7 @@ import 'package:doppio_dev_ixn/project/index.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:pedantic/pedantic.dart'; import 'package:uuid/uuid.dart'; +import 'package:file_manager/file_manager.dart' as manager; class ProjectPage extends StatefulWidget { static const String routeName = '/project'; @@ -94,7 +98,7 @@ class _ProjectPageState extends State { Spacer(), IconButton( onPressed: () async { - await _export(); + await _export(projectModel); }, tooltip: 'Export', icon: Icon(Icons.file_upload), @@ -144,8 +148,23 @@ class _ProjectPageState extends State { }); } - Future _export() async { + Future _export(ProjectModel projectModel) async { try { + var encoder = ZipEncoder(); + final archive = Archive(); + for (var locale in projectModel.locales) { + final mapWord = {}; + final result = {}; + projectModel.words.where((c) => c.locale == locale).map((e) => mapWord[e.keyId] = e.value).toList(); + for (var item in projectModel.keys) { + result['"${item.value}"'] = '"${mapWord[item.id]}"'; + } + final bytes = Utf8Codec().encode(result.toString()); + final archiveFile = ArchiveFile('$locale.json', bytes.length, bytes); + archive.addFile(archiveFile); + } + final bytesZip = encoder.encode(archive); + await manager.saveFile('${projectModel.name}-ixn.zip', binaryData: bytesZip); // projectScreen.import(filesData); } catch (_, stackTrace) { log(_?.toString(), name: 'ProjectsPage', error: _, stackTrace: stackTrace); diff --git a/lib/project_setting/project_setting_screen.dart b/lib/project_setting/project_setting_screen.dart index 91285f7..bfe22c9 100644 --- a/lib/project_setting/project_setting_screen.dart +++ b/lib/project_setting/project_setting_screen.dart @@ -37,7 +37,7 @@ class ProjectSettingScreenState extends State { void initState() { locales = kMaterialSupportedLanguages.toList(); locales.sort(); - localesList = {for (var code in locales) code: '$code - ${TranslateService.localesCountry[code]}'}; + localesList = {for (var code in locales) code: '$code - ${TranslateService.localeCountryName[code]}'}; super.initState(); } @@ -171,7 +171,7 @@ class ProjectSettingScreenState extends State { ), Expanded( child: Text( - '$code - ${TranslateService.localesCountry[code]}', + '$code - ${TranslateService.localeCountryName[code]}', overflow: TextOverflow.clip, ), ) diff --git a/lib/service/translate_service.dart b/lib/service/translate_service.dart index 9ffd8cf..859a395 100644 --- a/lib/service/translate_service.dart +++ b/lib/service/translate_service.dart @@ -20,7 +20,7 @@ class TranslateService { } /// {@template flutter.localizations.material.languages} - static Map localesCountry = { + static Map localeCountryName = { 'af': 'Afrikaans', 'am': 'Amharic', 'ar': 'Arabic', @@ -101,6 +101,345 @@ class TranslateService { 'zu': 'Zulu', }; + static Map countryName2Code = { + 'Afghanistan - Dari': 'prs-AF', + 'Afghanistan - Pashto': 'ps-AF', + 'Albania - Albanian': 'sq-AL', + 'Algeria - Arabic': 'ar-DZ', + 'Algeria - Tamazight (Latin)': 'tzm-DZ', + 'Argentina - Spanish': 'es-AR', + 'Armenia - Armenian': 'hy-AM', + 'Australia - English': 'en-AU', + 'Austria - German': 'de-AT', + 'Azerbaijan - Azeri (Cyrillic)': 'az-AZ', + 'Azerbaijan - Azeri (Latin)': 'az-AZ', + 'Bahrain - Arabic': 'ar-BH', + 'Bangladesh - Bengali': 'bn-BD', + 'Belarus - Belarusian': 'be-BY', + 'Belgium - Dutch': 'nl-BE', + 'Belgium - French': 'fr-BE', + 'Belize - English': 'en-BZ', + 'Bolivarian Republic of Venezuela - Spanish': 'es-VE', + 'Bolivia - Quechua': 'quz-BO', + 'Bolivia - Spanish': 'es-BO', + 'Bosnia and Herzegovina - Bosnian (Cyrillic)': 'bs-BA', + 'Bosnia and Herzegovina - Bosnian (Latin)': 'bs-BA', + 'Bosnia and Herzegovina - Croatian': 'hr-BA', + 'Bosnia and Herzegovina - Serbian (Cyrillic)': 'sr-BA', + 'Bosnia and Herzegovina - Serbian (Latin)': 'sr-BA', + 'Brazil - Portuguese': 'pt-BR', + 'Brunei Darussalam - Malay': 'ms-BN', + 'Bulgaria - Bulgarian': 'bg-BG', + 'Cambodia - Khmer': 'km-KH', + 'Canada - English': 'en-CA', + 'Canada - French': 'fr-CA', + 'Canada - Inuktitut (Latin)': 'iu-CA', + 'Canada - Inuktitut (Syllabics)': 'iu-CA', + 'Canada - Mohawk': 'moh-CA', + 'Caribbean - English': 'en-029', + 'Chile - Mapudungun': 'arn-CL', + 'Chile - Spanish': 'es-CL', + 'Colombia - Spanish': 'es-CO', + 'Costa Rica - Spanish': 'es-CR', + 'Croatia - Croatian': 'hr-HR', + 'Czech Republic - Czech': 'cs-CZ', + 'Denmark - Danish': 'da-DK', + 'Dominican Republic - Spanish': 'es-DO', + 'Ecuador - Quechua': 'quz-EC', + 'Ecuador - Spanish': 'es-EC', + 'Egypt - Arabic': 'ar-EG', + 'El Salvador - Spanish': 'es-SV', + 'Estonia - Estonian': 'et-EE', + 'Ethiopia - Amharic': 'am-ET', + 'Faroe Islands - Faroese': 'fo-FO', + 'Finland - Finnish': 'fi-FI', + 'Finland - Sami (Inari)': 'smn-FI', + 'Finland - Sami (Northern)': 'se-FI', + 'Finland - Sami (Skolt)': 'sms-FI', + 'Finland - Swedish': 'sv-FI', + 'France - Alsatian': 'gsw-FR', + 'France - Breton': 'br-FR', + 'France - Corsican': 'co-FR', + 'France - French': 'fr-FR', + 'France - Occitan': 'oc-FR', + 'Georgia - Georgian': 'ka-GE', + 'Germany - German': 'de-DE', + 'Germany - Lower Sorbian': 'dsb-DE', + 'Germany - Upper Sorbian': 'hsb-DE', + 'Greece - Greek': 'el-GR', + 'Greenland - Greenlandic': 'kl-GL', + 'Guatemala - K\'iche': 'qut-GT', + 'Guatemala - Spanish': 'es-GT', + 'Honduras - Spanish': 'es-HN', + 'Hong Kong S.A.R. - Chinese (Traditional) Legacy': 'zh-HK', + 'Hungary - Hungarian': 'hu-HU', + 'Iceland - Icelandic': 'is-IS', + 'India - Assamese': 'as-IN', + 'India - Bengali': 'bn-IN', + 'India - English': 'en-IN', + 'India - Gujarati': 'gu-IN', + 'India - Hindi': 'hi-IN', + 'India - Kannada': 'kn-IN', + 'India - Konkani': 'kok-IN', + 'India - Malayalam': 'ml-IN', + 'India - Marathi': 'mr-IN', + 'India - Oriya': 'or-IN', + 'India - Punjabi': 'pa-IN', + 'India - Sanskrit': 'sa-IN', + 'India - Tamil': 'ta-IN', + 'India - Telugu': 'te-IN', + 'Indonesia - Indonesian': 'id-ID', + 'Iran - Persian': 'fa-IR', + 'Iraq - Arabic': 'ar-IQ', + 'Ireland - English': 'en-IE', + 'Ireland - Irish': 'ga-IE', + 'Islamic Republic of Pakistan - Urdu': 'ur-PK', + 'Israel - Hebrew': 'he-IL', + 'Italy - Italian': 'it-IT', + 'Jamaica - English': 'en-JM', + 'Japan - Japanese': 'ja-JP', + 'Jordan - Arabic': 'ar-JO', + 'Kazakhstan - Kazakh': 'kk-KZ', + 'Kenya - Kiswahili': 'sw-KE', + 'Korea - Korean': 'ko-KR', + 'Kuwait - Arabic': 'ar-KW', + 'Kyrgyzstan - Kyrgyz': 'ky-KG', + 'Lao P.D.R. - Lao': 'lo-LA', + 'Latvia - Latvian': 'lv-LV', + 'Lebanon - Arabic': 'ar-LB', + 'Libya - Arabic': 'ar-LY', + 'Liechtenstein - German': 'de-LI', + 'Lithuania - Lithuanian': 'lt-LT', + 'Luxembourg - French': 'fr-LU', + 'Luxembourg - German': 'de-LU', + 'Luxembourg - Luxembourgish': 'lb-LU', + 'Macao S.A.R. - Chinese (Traditional) Legacy': 'zh-MO', + 'Macedonia (FYROM) - Macedonian (FYROM)': 'mk-MK', + 'Malaysia - English': 'en-MY', + 'Malaysia - Malay': 'ms-MY', + 'Maldives - Divehi': 'dv-MV', + 'Malta - Maltese': 'mt-MT', + 'Mexico - Spanish': 'es-MX', + 'Mongolia - Mongolian (Cyrillic)': 'mn-MN', + 'Montenegro - Serbian (Cyrillic)': 'sr-ME', + 'Montenegro - Serbian (Latin)': 'sr-ME', + 'Morocco - Arabic': 'ar-MA', + 'Nepal - Nepali': 'ne-NP', + 'Netherlands - Dutch': 'nl-NL', + 'Netherlands - Frisian': 'fy-NL', + 'New Zealand - English': 'en-NZ', + 'New Zealand - Maori': 'mi-NZ', + 'Nicaragua - Spanish': 'es-NI', + 'Nigeria - Hausa (Latin)': 'ha-NG', + 'Nigeria - Igbo': 'ig-NG', + 'Nigeria - Yoruba': 'yo-NG', + 'Norway - Norwegian (Bokmal)': 'nb-NO', + 'Norway - Norwegian (Nynorsk)': 'nn-NO', + 'Norway - Sami (Lule)': 'smj-NO', + 'Norway - Sami (Northern)': 'se-NO', + 'Norway - Sami (Southern)': 'sma-NO', + 'Oman - Arabic': 'ar-OM', + 'Panama - Spanish': 'es-PA', + 'Paraguay - Spanish': 'es-PY', + 'People\'s Republic of China - Chinese (Simplified) Legacy': 'zh-CN', + 'People\'s Republic of China - Mongolian (Traditional Mongolian)': 'mn-CN', + 'People\'s Republic of China - Tibetan': 'bo-CN', + 'People\'s Republic of China - Uyghur': 'ug-CN', + 'People\'s Republic of China - Yi': 'ii-CN', + 'Peru - Quechua': 'quz-PE', + 'Peru - Spanish': 'es-PE', + 'Philippines - Filipino': 'fil-PH', + 'Poland - Polish': 'pl-PL', + 'Portugal - Portuguese': 'pt-PT', + 'Principality of Monaco - French': 'fr-MC', + 'Puerto Rico - Spanish': 'es-PR', + 'Qatar - Arabic': 'ar-QA', + 'Republic of the Philippines - English': 'en-PH', + 'Romania - Romanian': 'ro-RO', + 'Russia - Bashkir': 'ba-RU', + 'Russia - Russian': 'ru-RU', + 'Russia - Tatar': 'tt-RU', + 'Russia - Yakut': 'sah-RU', + 'Rwanda - Kinyarwanda': 'rw-RW', + 'Saudi Arabia - Arabic': 'ar-SA', + 'Senegal - Wolof': 'wo-SN', + 'Serbia - Serbian (Cyrillic)': 'sr-RS', + 'Serbia - Serbian (Latin)': 'sr-RS', + 'Serbia and Montenegro (Former) - Serbian (Cyrillic)': 'sr-CS', + 'Serbia and Montenegro (Former) - Serbian (Latin)': 'sr-CS', + 'Singapore - Chinese (Simplified) Legacy': 'zh-SG', + 'Singapore - English': 'en-SG', + 'Slovakia - Slovak': 'sk-SK', + 'Slovenia - Slovenian': 'sl-SI', + 'South Africa - Afrikaans': 'af-ZA', + 'South Africa - English': 'en-ZA', + 'South Africa - isiXhosa': 'xh-ZA', + 'South Africa - isiZulu': 'zu-ZA', + 'South Africa - Sesotho sa Leboa': 'nso-ZA', + 'South Africa - Setswana': 'tn-ZA', + 'Spain - Basque': 'eu-ES', + 'Spain - Catalan': 'ca-ES', + 'Spain - Galician': 'gl-ES', + 'Spain - Spanish': 'es-ES', + 'Sri Lanka - Sinhala': 'si-LK', + 'Sweden - Sami (Lule)': 'smj-SE', + 'Sweden - Sami (Northern)': 'se-SE', + 'Sweden - Sami (Southern)': 'sma-SE', + 'Sweden - Swedish': 'sv-SE', + 'Switzerland - French': 'fr-CH', + 'Switzerland - German': 'de-CH', + 'Switzerland - Italian': 'it-CH', + 'Switzerland - Romansh': 'rm-CH', + 'Syria - Arabic': 'ar-SY', + 'Syria - Syriac': 'syr-SY', + 'Taiwan - Chinese (Traditional) Legacy': 'zh-TW', + 'Tajikistan - Tajik (Cyrillic)': 'tg-TJ', + 'Thailand - Thai': 'th-TH', + 'Trinidad and Tobago - English': 'en-TT', + 'Tunisia - Arabic': 'ar-TN', + 'Turkey - Turkish': 'tr-TR', + 'Turkmenistan - Turkmen': 'tk-TM', + 'U.A.E. - Arabic': 'ar-AE', + 'Ukraine - Ukrainian': 'uk-UA', + 'United Kingdom - English': 'en-GB', + 'United Kingdom - Scottish Gaelic': 'gd-GB', + 'United Kingdom - Welsh': 'cy-GB', + 'United States - English': 'en-US', + 'United States - Spanish': 'es-US', + 'Uruguay - Spanish': 'es-UY', + 'Uzbekistan - Uzbek (Cyrillic)': 'uz-UZ', + 'Uzbekistan - Uzbek (Latin)': 'uz-UZ', + 'Vietnam - Vietnamese': 'vi-VN', + 'Yemen - Arabic': 'ar-YE', + 'Zimbabwe - English': 'en-ZW' + }; + + static Map localeCountry = { + 'prs': 'AF', + 'ps': 'AF', + 'sq': 'AL', + 'ar': 'DZ', + 'tzm': 'DZ', + 'es': 'AR', + 'hy': 'AM', + 'en': 'AU', + 'de': 'AT', + 'az': 'AZ', + 'bn': 'BD', + 'be': 'BY', + 'nl': 'BE', + 'fr': 'BE', + 'quz': 'BO', + 'bs': 'BA', + 'hr': 'BA', + 'sr': 'BA', + 'pt': 'BR', + 'ms': 'BN', + 'bg': 'BG', + 'km': 'KH', + 'iu': 'CA', + 'moh': 'CA', + 'arn': 'CL', + 'cs': 'CZ', + 'da': 'DK', + 'et': 'EE', + 'am': 'ET', + 'fo': 'FO', + 'fi': 'FI', + 'smn': 'FI', + 'se': 'FI', + 'sms': 'FI', + 'sv': 'FI', + 'gsw': 'FR', + 'br': 'FR', + 'co': 'FR', + 'oc': 'FR', + 'ka': 'GE', + 'dsb': 'DE', + 'hsb': 'DE', + 'el': 'GR', + 'kl': 'GL', + 'qut': 'GT', + 'zh': 'HK', + 'hu': 'HU', + 'is': 'IS', + 'as': 'IN', + 'gu': 'IN', + 'hi': 'IN', + 'kn': 'IN', + 'kok': 'IN', + 'ml': 'IN', + 'mr': 'IN', + 'or': 'IN', + 'pa': 'IN', + 'sa': 'IN', + 'ta': 'IN', + 'te': 'IN', + 'id': 'ID', + 'fa': 'IR', + 'ga': 'IE', + 'ur': 'PK', + 'he': 'IL', + 'it': 'IT', + 'ja': 'JP', + 'kk': 'KZ', + 'sw': 'KE', + 'ko': 'KR', + 'ky': 'KG', + 'lo': 'LA', + 'lv': 'LV', + 'lt': 'LT', + 'lb': 'LU', + 'mk': 'MK', + 'dv': 'MV', + 'mt': 'MT', + 'mn': 'MN', + 'ne': 'NP', + 'fy': 'NL', + 'mi': 'NZ', + 'ha': 'NG', + 'ig': 'NG', + 'yo': 'NG', + 'nb': 'NO', + 'nn': 'NO', + 'smj': 'NO', + 'sma': 'NO', + 'bo': 'CN', + 'ug': 'CN', + 'ii': 'CN', + 'fil': 'PH', + 'pl': 'PL', + 'ro': 'RO', + 'ba': 'RU', + 'ru': 'RU', + 'tt': 'RU', + 'sah': 'RU', + 'rw': 'RW', + 'wo': 'SN', + 'sk': 'SK', + 'sl': 'SI', + 'af': 'ZA', + 'xh': 'ZA', + 'zu': 'ZA', + 'nso': 'ZA', + 'tn': 'ZA', + 'eu': 'ES', + 'ca': 'ES', + 'gl': 'ES', + 'si': 'LK', + 'rm': 'CH', + 'syr': 'SY', + 'tg': 'TJ', + 'th': 'TH', + 'tr': 'TR', + 'tk': 'TM', + 'uk': 'UA', + 'gd': 'GB', + 'cy': 'GB', + 'uz': 'UZ', + 'vi': 'VN', + }; + Future>> importFiles() async { final newFiles = (await file_access.open(true, false, allowedTypes: ['json', 'arb'])); final filesData = >{}; @@ -112,7 +451,7 @@ class TranslateService { if (filesData.containsKey(locale)) { throw Exception('dublicate locale'); } - if (!TranslateService.localesCountry.containsKey(locale)) { + if (!TranslateService.localeCountryName.containsKey(locale)) { throw Exception(TranslateService().locale.error_locale_notsupport(locale, item.path)); } filesData[locale] = json; diff --git a/lib/widget/lang_dropdown.dart b/lib/widget/lang_dropdown.dart index 0fce9cb..ce77dee 100644 --- a/lib/widget/lang_dropdown.dart +++ b/lib/widget/lang_dropdown.dart @@ -48,7 +48,7 @@ class _LangDropdownWidgetState extends State { child: Container( width: widget.width, child: Text( - '$_code - ${TranslateService.localesCountry[_code]}', + '$_code - ${TranslateService.localeCountryName[_code]}', overflow: TextOverflow.clip, maxLines: 1, softWrap: true, diff --git a/pubspec.yaml b/pubspec.yaml index 73df6b1..127b376 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -54,6 +54,16 @@ dependencies: rxdart: 0.24.0 bot_toast: 3.0.0 + file_access: + git: https://github.com/Gorniv/file_access + + file_manager: + git: + url: https://github.com/rodydavis/file_manager + ref: master + path: file_manager + archive: 2.0.13 + # dependency_overrides: # path: 1.7.0 @@ -79,8 +89,6 @@ dev_dependencies: translator: #0.1.4 git: url: https://github.com/Gorniv/google-translator - file_access: - git: https://github.com/Gorniv/file_access # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec