From 39aa82f9f2997efe54b99beabb6da325944815f9 Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Mon, 9 Jan 2017 13:50:57 +1300 Subject: [PATCH] Implement translation for hint text (#5) --- code/TextTargetLengthExtension.php | 7 +++++++ javascript/text-target-length.js | 10 +++++----- lang/_manifest_exclude | 0 lang/en.yml | 7 +++++++ 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 lang/_manifest_exclude create mode 100644 lang/en.yml diff --git a/code/TextTargetLengthExtension.php b/code/TextTargetLengthExtension.php index aec4eb9..7bb81be 100755 --- a/code/TextTargetLengthExtension.php +++ b/code/TextTargetLengthExtension.php @@ -34,6 +34,13 @@ public function setTargetLength($idealCharCount, $minCharCount = null, $maxCharC $field->setAttribute('data-target-ideal-length', $idealCharCount); $field->setAttribute('data-target-min-length', $minCharCount); $field->setAttribute('data-target-max-length', $maxCharCount); + + $field->setAttribute('data-hint-length-target', _t('TextTargetLength.LengthTarget', 'Length target: %s% %s')); + $field->setAttribute('data-hint-length-tooshort', _t('TextTargetLength.LengthTooShort', 'Keep going!')); + $field->setAttribute('data-hint-length-toolong', _t('TextTargetLength.LengthTooLong', 'Too long')); + $field->setAttribute('data-hint-length-adequate', _t('TextTargetLength.LengthAdequate', 'Okay')); + $field->setAttribute('data-hint-length-ideal', _t('TextTargetLength.LengthIdeal', 'Great!')); + Requirements::javascript(FRAMEWORK_DIR.'/thirdparty/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR.'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript(TEXTTARGETLENGTH_DIR.'/javascript/text-target-length.js'); diff --git a/javascript/text-target-length.js b/javascript/text-target-length.js index 0fe0d17..4a59b1e 100755 --- a/javascript/text-target-length.js +++ b/javascript/text-target-length.js @@ -13,20 +13,20 @@ var min = field.data('targetMinLength'); var max = field.data('targetMaxLength'); var targetFulfilled = Math.round((charCount / ideal)*20)*5; //5% increments - var remark = 'Great!'; + var remark = field.data('hintLengthIdeal'); var remarkClass = 'good'; if ((charCount >= min && charCount < ((min + ideal) / 2)) || (charCount <= max && charCount > ((max + ideal) / 2))) { - remark = 'Okay'; + remark = field.data('hintLengthAdequate'); } else if (charCount < min) { - remark = 'Keep going!'; + remark = field.data('hintLengthTooshort'); remarkClass = 'under'; if (charCount === 0) remark = ''; } else if (charCount > max) { - remark = 'Too long' + remark = field.data('hintLengthToolong'); remarkClass = 'over'; } countEl.attr('class', remarkClass + ' target-length-count'); - countEl.html('Length target: ' + targetFulfilled + '% ' + remark + ''); + countEl.html(field.data('hintLengthTarget').replace('{value}', targetFulfilled).replace('{remark}', remark)); field.data('previousCount', charCount); }, getText: function() { diff --git a/lang/_manifest_exclude b/lang/_manifest_exclude new file mode 100644 index 0000000..e69de29 diff --git a/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..660fa50 --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,7 @@ +en: + TextTargetLength: + LengthTarget: "Length target: {value}% {remark}" + LengthTooShort: "Keep going!" + LengthTooLong: "Too long" + LengthAdequate: "Okay" + LengthIdeal: "Great!"