Skip to content

Commit

Permalink
Implement translation for hint text (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
satrun77 authored and jonom committed Jan 9, 2017
1 parent a2b9de5 commit 39aa82f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions code/TextTargetLengthExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: <b>%s%</b> <i>%s</i>'));
$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');
Expand Down
10 changes: 5 additions & 5 deletions javascript/text-target-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: <b>' + targetFulfilled + '%</b> <i>' + remark + '</i>');
countEl.html(field.data('hintLengthTarget').replace('{value}', targetFulfilled).replace('{remark}', remark));
field.data('previousCount', charCount);
},
getText: function() {
Expand Down
Empty file added lang/_manifest_exclude
Empty file.
7 changes: 7 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
en:
TextTargetLength:
LengthTarget: "Length target: <b>{value}%</b> <i>{remark}</i>"
LengthTooShort: "Keep going!"
LengthTooLong: "Too long"
LengthAdequate: "Okay"
LengthIdeal: "Great!"

0 comments on commit 39aa82f

Please sign in to comment.