From 2ac23cc3c7c1c047f486ec720ba8fbbb8c5e9af9 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 26 Mar 2016 14:28:34 +1100 Subject: [PATCH] More peer review of #1856 Separation of concerns, the language file shouldn't really be treated as a data source for the supported encoding options. --- modules/backend/lang/en/lang.php | 36 +++++++++++++------------- modules/backend/lang/fr/lang.php | 36 +++++++++++++------------- modules/backend/models/ImportModel.php | 29 +++++++++++++++++++-- 3 files changed, 63 insertions(+), 38 deletions(-) diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 9a2bfc266..211bcad61 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -377,24 +377,24 @@ return [ 'encoding_not_supported_error' => 'Source file encoding is not recognized. Please select the custom file format option with the proper encoding to import your file.', 'encoding_format' => 'File encoding', 'encodings' => [ - 'utf-8' => 'UTF-8', - 'us-ascii' => 'US-ASCII', - 'iso-8859-1' => 'ISO-8859-1 (Latin-1, Western European)', - 'iso-8859-2' => 'ISO-8859-2 (Latin-2, Central European)', - 'iso-8859-3' => 'ISO-8859-3 (Latin-3, South European)', - 'iso-8859-4' => 'ISO-8859-4 (Latin-4, North European)', - 'iso-8859-5' => 'ISO-8859-5 (Latin, Cyrillic)', - 'iso-8859-6' => 'ISO-8859-6 (Latin, Arabic)', - 'iso-8859-7' => 'ISO-8859-7 (Latin, Greek)', - 'iso-8859-8' => 'ISO-8859-8 (Latin, Hebrew)', - 'iso-8859-0' => 'ISO-8859-9 (Latin-5, Turkish)', - 'iso-8859-10' => 'ISO-8859-10 (Latin-6, Nordic)', - 'iso-8859-11' => 'ISO-8859-11 (Latin, Thai)', - 'iso-8859-13' => 'ISO-8859-13 (Latin-7, Baltic Rim)', - 'iso-8859-14' => 'ISO-8859-14 (Latin-8, Celtic)', - 'iso-8859-15' => 'ISO-8859-15 (Latin-9, Western European revision with euro sign)', - 'Windows-1251' => 'Windows-1251 (CP1251)', - 'Windows-1252' => 'Windows-1252 (CP1252)' + 'utf_8' => 'UTF-8', + 'us_ascii' => 'US-ASCII', + 'iso_8859_1' => 'ISO-8859-1 (Latin-1, Western European)', + 'iso_8859_2' => 'ISO-8859-2 (Latin-2, Central European)', + 'iso_8859_3' => 'ISO-8859-3 (Latin-3, South European)', + 'iso_8859_4' => 'ISO-8859-4 (Latin-4, North European)', + 'iso_8859_5' => 'ISO-8859-5 (Latin, Cyrillic)', + 'iso_8859_6' => 'ISO-8859-6 (Latin, Arabic)', + 'iso_8859_7' => 'ISO-8859-7 (Latin, Greek)', + 'iso_8859_8' => 'ISO-8859-8 (Latin, Hebrew)', + 'iso_8859_0' => 'ISO-8859-9 (Latin-5, Turkish)', + 'iso_8859_10' => 'ISO-8859-10 (Latin-6, Nordic)', + 'iso_8859_11' => 'ISO-8859-11 (Latin, Thai)', + 'iso_8859_13' => 'ISO-8859-13 (Latin-7, Baltic Rim)', + 'iso_8859_14' => 'ISO-8859-14 (Latin-8, Celtic)', + 'iso_8859_15' => 'ISO-8859-15 (Latin-9, Western European revision with euro sign)', + 'windows_1251' => 'Windows-1251 (CP1251)', + 'windows_1252' => 'Windows-1252 (CP1252)' ], ], ]; diff --git a/modules/backend/lang/fr/lang.php b/modules/backend/lang/fr/lang.php index dd24e4856..080ba1ad8 100644 --- a/modules/backend/lang/fr/lang.php +++ b/modules/backend/lang/fr/lang.php @@ -361,24 +361,24 @@ return [ 'encoding_not_supported_error' => 'L’encodage de votre fichier source n’est pas reconnu. Veuillez sélectionner le format d’import personnalisé avec l’encodage adapté pour importer votre fichier.', 'encoding_format' => 'Encodage du fichier', 'encodings' => [ - 'utf-8' => 'UTF-8', - 'us-ascii' => 'US-ASCII', - 'iso-8859-1' => 'ISO-8859-1 (Latin-1, européen occidental)', - 'iso-8859-2' => 'ISO-8859-2 (Latin-2, européen central)', - 'iso-8859-3' => 'ISO-8859-3 (Latin-3, européen du Sud)', - 'iso-8859-4' => 'ISO-8859-4 (Latin-4, européen du Nord)', - 'iso-8859-5' => 'ISO-8859-5 (Latin, cyrillique)', - 'iso-8859-6' => 'ISO-8859-6 (Latin, arabe)', - 'iso-8859-7' => 'ISO-8859-7 (Latin, grec)', - 'iso-8859-8' => 'ISO-8859-8 (Latin, hébreu)', - 'iso-8859-0' => 'ISO-8859-9 (Latin-5, turc)', - 'iso-8859-10' => 'ISO-8859-10 (Latin-6, nordique)', - 'iso-8859-11' => 'ISO-8859-11 (Latin, thaï)', - 'iso-8859-13' => 'ISO-8859-13 (Latin-7, balte)', - 'iso-8859-14' => 'ISO-8859-14 (Latin-8, celtique)', - 'iso-8859-15' => 'ISO-8859-15 (Latin-9, européen occidental révisé avec le signe euro)', - 'Windows-1251' => 'Windows-1251 (CP1251)', - 'Windows-1252' => 'Windows-1252 (CP1252)' + 'utf_8' => 'UTF-8', + 'us_ascii' => 'US-ASCII', + 'iso_8859_1' => 'ISO-8859-1 (Latin-1, européen occidental)', + 'iso_8859_2' => 'ISO-8859-2 (Latin-2, européen central)', + 'iso_8859_3' => 'ISO-8859-3 (Latin-3, européen du Sud)', + 'iso_8859_4' => 'ISO-8859-4 (Latin-4, européen du Nord)', + 'iso_8859_5' => 'ISO-8859-5 (Latin, cyrillique)', + 'iso_8859_6' => 'ISO-8859-6 (Latin, arabe)', + 'iso_8859_7' => 'ISO-8859-7 (Latin, grec)', + 'iso_8859_8' => 'ISO-8859-8 (Latin, hébreu)', + 'iso_8859_0' => 'ISO-8859-9 (Latin-5, turc)', + 'iso_8859_10' => 'ISO-8859-10 (Latin-6, nordique)', + 'iso_8859_11' => 'ISO-8859-11 (Latin, thaï)', + 'iso_8859_13' => 'ISO-8859-13 (Latin-7, balte)', + 'iso_8859_14' => 'ISO-8859-14 (Latin-8, celtique)', + 'iso_8859_15' => 'ISO-8859-15 (Latin-9, européen occidental révisé avec le signe euro)', + 'windows_1251' => 'Windows-1251 (CP1251)', + 'windows_1252' => 'Windows-1252 (CP1252)' ], ], ]; diff --git a/modules/backend/models/ImportModel.php b/modules/backend/models/ImportModel.php index 870a4146d..0a7fbfde8 100644 --- a/modules/backend/models/ImportModel.php +++ b/modules/backend/models/ImportModel.php @@ -1,5 +1,6 @@ getLocalPath(); } - /** * Returns all available encodings values from the localization config * @return array */ public function getFormatEncodingOptions() { - return Lang::get('backend::lang.import_export.encodings'); + $options = [ + 'utf-8', + 'us-ascii', + 'iso-8859-1', + 'iso-8859-2', + 'iso-8859-3', + 'iso-8859-4', + 'iso-8859-5', + 'iso-8859-6', + 'iso-8859-7', + 'iso-8859-8', + 'iso-8859-0', + 'iso-8859-10', + 'iso-8859-11', + 'iso-8859-13', + 'iso-8859-14', + 'iso-8859-15', + 'Windows-1251', + 'Windows-1252' + ]; + + $translated = array_map(function($option){ + return Lang::get('backend::lang.import_export.encodings.'.Str::slug($option, '_')); + }, $options); + + return array_combine($options, $translated); } //