From 0e7d8b33a06a2ee83026a914ae6910f78f599ce8 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Tue, 23 Feb 2021 23:53:52 +0300 Subject: [PATCH] few more checks for translation values validation --- .../language/en-GB/en-GB.com_jedchecker.ini | 6 ++++++ .../com_jedchecker/libraries/rules/language.php | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini index 9119238..c350413 100644 --- a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini +++ b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini @@ -94,3 +94,9 @@ COM_JEDCHECKER_LANG_TRANSLATION_ERROR="Incorrect translation string" COM_JEDCHECKER_LANG_TRANSLATION_QUOTES="All translation strings should be in double quotation marks" COM_JEDCHECKER_LANG_TRANSLATION_EMPTY="Empty translation string" COM_JEDCHECKER_LANG_QQ_DEPRECATED="Usage of \"_QQ_\" is deprecated since Joomla! 3.9. Use escaped double quotes (\\\") instead" +COM_JEDCHECKER_LANG_UNESCAPED_QUOTE="Unescaped double quotation mark found" +COM_JEDCHECKER_LANG_VARIABLE_REF="A variable reference found in the translation string." +COM_JEDCHECKER_LANG_RECOMMEND_ARGNUM="Substituted values may have another order in other languages. To simplify work of translators, it's recommended to use Argnum specification, see https://www.php.net/manual/en/function.sprintf.php for details" +COM_JEDCHECKER_TOOLBAR_CHECK="Check" +COM_JEDCHECKER_TOOLBAR_CLEAR="Clear" +COM_JEDCHECKER_CLICK_TO_VIEW_DETAILS="Click to View Details" diff --git a/administrator/components/com_jedchecker/libraries/rules/language.php b/administrator/components/com_jedchecker/libraries/rules/language.php index d80dacd..359b09f 100644 --- a/administrator/components/com_jedchecker/libraries/rules/language.php +++ b/administrator/components/com_jedchecker/libraries/rules/language.php @@ -209,6 +209,18 @@ class JedcheckerRulesLanguage extends JEDcheckerRule $this->report->addCompat($file, JText::_('COM_JEDCHECKER_LANG_QQ_DEPRECATED'), $startLineno, $line); } + $value = str_replace('"_QQ_"', '\"', $value); + + if (preg_match('/[^\\\\]"/', $value)) + { + $this->report->addWarning($file, JText::_('COM_JEDCHECKER_LANG_UNESCAPED_QUOTE'), $startLineno, $line); + } + + if (strpos($value, '${') !== false) + { + $this->report->addWarning($file, JText::_('COM_JEDCHECKER_LANG_VARIABLE_REF'), $startLineno, $line); + } + // Count %... formats in the string $count1 = preg_match_all('/(?<=^|[^%])%(?=[-+0 ]?\w)/', $value);