From c55f92f6f1cc5c4eb97708b19653e9be885aec43 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 11 Aug 2014 17:05:30 -0500 Subject: [PATCH] i18n: Make textarea inputs translatable --- include/class.forms.php | 3 ++- include/staff/dynamic-form.inc.php | 3 ++- include/staff/settings-system.inc.php | 2 +- .../templates/dynamic-field-config.tmpl.php | 7 +++--- scp/js/jquery.translatable.js | 22 +++++++++++-------- scp/js/scp.js | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/class.forms.php b/include/class.forms.php index 77248c828..dafc403f1 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -781,7 +781,8 @@ class TextareaField extends FormField { 'placeholder' => new TextboxField(array( 'id'=>5, 'label'=>__('Placeholder'), 'required'=>false, 'default'=>'', 'hint'=>__('Text shown in before any input from the user'), - 'configuration'=>array('size'=>40, 'length'=>40), + 'configuration'=>array('size'=>40, 'length'=>40, + 'translatable'=>$this->getTranslateTag('placeholder')), )), ); } diff --git a/include/staff/dynamic-form.inc.php b/include/staff/dynamic-form.inc.php index 2e429debb..b79a4320d 100644 --- a/include/staff/dynamic-form.inc.php +++ b/include/staff/dynamic-form.inc.php @@ -50,7 +50,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </tr> <tr> <td width="180"><?php echo __('Instructions'); ?>:</td> - <td><textarea name="instructions" rows="3" cols="40"><?php + <td><textarea name="instructions" rows="3" cols="40" + data-translate-tag="<?php echo $trans['instructions']; ?>"><?php echo $info['instructions']; ?></textarea> <i class="help-tip icon-question-sign" href="#form_instructions"></i> </td> diff --git a/include/staff/settings-system.inc.php b/include/staff/settings-system.inc.php index 748041692..3a87722b5 100644 --- a/include/staff/settings-system.inc.php +++ b/include/staff/settings-system.inc.php @@ -208,7 +208,7 @@ $gmtime = Misc::gmtime(); </td><td style="border:none;"> <a href="#<?php echo $lang; ?>" onclick="javascript: - if (confirm(__('You sure?'))) { + if (confirm('<?php echo __('You sure?'); ?>'))) { $(this).closest('form').find('input[name=\'secondary_langs[]\'][value=' + $(this).attr('href').substr(1) + ']').val(''); $(this).closest('tr').remove(); diff --git a/include/staff/templates/dynamic-field-config.tmpl.php b/include/staff/templates/dynamic-field-config.tmpl.php index 8051e31ef..d9db95352 100644 --- a/include/staff/templates/dynamic-field-config.tmpl.php +++ b/include/staff/templates/dynamic-field-config.tmpl.php @@ -44,8 +44,9 @@ <em style="color:gray;display:inline-block"> <?php echo __('Help text shown with the field'); ?></em> </div> - <div> - <textarea style="width:100%" name="hint" rows="2" cols="40"><?php + <div style="width:100%"> + <textarea style="width:90%; width:calc(100% - 20px)" name="hint" rows="2" cols="40" + data-translate-tag="<?php echo $field->getTranslateTag('hint'); ?>"><?php echo Format::htmlchars($field->get('hint')); ?></textarea> </div> </div> @@ -63,5 +64,5 @@ <div class="clear"></div> <script type="text/javascript"> // Make translatable fields translatable - $('input[data-translate-tag]').translatable(); + $('input[data-translate-tag], textarea[data-translate-tag]').translatable(); </script> diff --git a/scp/js/jquery.translatable.js b/scp/js/jquery.translatable.js index 8726abca6..7e06f3fdf 100644 --- a/scp/js/jquery.translatable.js +++ b/scp/js/jquery.translatable.js @@ -9,11 +9,13 @@ if (!this.$element.data('translateTag')) return; - var self = this; - this.fetch('ajax.php/i18n/langs').then(function(json) { - self.langs = json; - if (Object.keys(self.langs).length) self.decorate(); - }); + this.shown = false; + this.populated = false; + + this.fetch('ajax.php/i18n/langs').then($.proxy(function(json) { + this.langs = json; + if (Object.keys(this.langs).length) this.decorate(); + }, this)); }, // Class-static variables urlcache = {}; @@ -42,12 +44,14 @@ this.$container = $('<div class="translatable"></div>') .prependTo(this.$element.parent()) .append(this.$element); + this.$container.wrap('<div style="display:inline-block;position:relative;width:inherit"></div>'); this.$button = $(this.options.button).insertAfter(this.$container); - //this.$menu.append('<a class="close pull-right" href=""><i class="icon-remove-circle"></i></a>') - // .on('click', $.proxy(this.hide, this)); + this.$menu.append($('<span class="close"><i class="icon-remove"></i></span>') + .on('click', $.proxy(this.hide, this))); + if (this.$element.is('textarea')) { + this.$container.addClass('textarea'); + } this.$menu.append(this.$translations).append(this.$footer); - this.shown = false; - this.populated = false; this.$button.on('click', $.proxy(this.toggle, this)); diff --git a/scp/js/scp.js b/scp/js/scp.js index a9a67b04f..1650871ec 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -445,7 +445,7 @@ var scp_prep = function() { }); // Make translatable fields translatable - $('input[data-translate-tag]').translatable(); + $('input[data-translate-tag], textarea[data-translate-tag]').translatable(); }; $(document).ready(scp_prep); -- GitLab