Skip to content

Commit

Permalink
Implementing weights translations
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathon-love committed Jul 29, 2023
1 parent 614a1d6 commit 959640e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
35 changes: 28 additions & 7 deletions client/common/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class I18n {
return this._availableLanguages;
}

_(key, formats) {
_(key, formats, options={ prefix: '', postfix: '' }) {
let value = null;
if ( ! this.jed)
value = key;
else
value = this.jed.dcnpgettext(undefined, undefined, key);

if (formats)
value = this.format(value, formats);
value = this.format(value, formats, options);
return value;
}

Expand Down Expand Up @@ -97,12 +97,33 @@ class I18n {
return value;
}

format(value, formats) {
let newValue = value;
for (let name in formats) {
newValue = newValue.replace(`{${name}}`, formats[name]);
__(compound, options={ prefix: '', postfix: '' }) {
const parts = compound.split('\u0004');
if (parts.length === 1) {
// not a translatable string
return parts[0];
}
else if (parts.length < 3) {
return _(parts[0]);
}
else {
const key = parts[1];
const values = JSON.parse(parts[2]);
return _(key, values, options);
}
}

format(fstring, values, options={ prefix: '', postfix: '' }) {
const { prefix, postfix } = options;
if (typeof values === 'string') {
return fstring.replace('{}', `${ prefix }${ values }${ postfix }`);
}
else {
let value = fstring;
for (let name in values)
value = value.replace(`{${name}}`, `${ prefix }${ values[name] }${ postfix }`);
return value;
}
return newValue;
}

isRTL() {
Expand Down
13 changes: 13 additions & 0 deletions client/main/strings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// these are just extra strings we need translated, but don't fit anywhere.

// from jmvcore
_('The data is weighted, however this analysis does not support weights. This analysis used the data unweighted.')
_('The data is weighted by the variable {}, however this analysis does not support non-integer weights. The weights were rounded to the nearest integer.')
_('The data is weighted by the variable {}.')


// these *were* in our translations, and apparently aren't any more
// but i feel like we're going to need them in the future
_('Error')
_('Unable to save')
7 changes: 6 additions & 1 deletion client/resultsview/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Backbone.$ = $;

const Elem = require('./element');

import i18n from '../common/i18n';


export const NoticeModel = Elem.Model.extend({
defaults : {
Expand Down Expand Up @@ -64,7 +66,10 @@ export const NoticeView = Elem.View.extend({

let $content = this.$el.find('.content');
this.$el.find('a[href]').off('click');
$content.html(doc.content);

const content = i18n.__(doc.content, { prefix: '<strong>', postfix: '</strong>' });
$content.html(content);

this.$el.find('a[href]').on('click', (event) => this._handleLinkClick(event));
},
_handleLinkClick(event) {
Expand Down
2 changes: 1 addition & 1 deletion i18n
Submodule i18n updated 30 files
+124 −12 src/ar.po
+119 −9 src/ca.po
+504 −391 src/catalog.pot
+203 −91 src/cs.po
+116 −6 src/da.po
+120 −11 src/de.po
+132 −25 src/el.po
+116 −6 src/en.po
+119 −9 src/es.po
+120 −11 src/fr.po
+118 −8 src/hr.po
+116 −6 src/hu.po
+125 −16 src/id.po
+124 −15 src/it.po
+119 −9 src/ja.po
+160 −25 src/kk.po
+119 −9 src/ko.po
+119 −9 src/ml.po
+172 −41 src/nl.po
+118 −8 src/nn.po
+120 −11 src/no.po
+123 −14 src/pl.po
+121 −12 src/pt.po
+126 −16 src/ru.po
+118 −8 src/sl.po
+116 −6 src/sv.po
+259 −148 src/tr.po
+120 −11 src/uk.po
+119 −9 src/zh-cn.po
+134 −40 src/zh-tw.po
2 changes: 1 addition & 1 deletion jmvcore
Submodule jmvcore updated 1 files
+9 −2 R/analysis.R
2 changes: 1 addition & 1 deletion server/jamovi/server/analyses/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _update(self, *, just_created=False):
weights = self.options.get_value('weights')
if weights:
bolded = f'<strong>{ html.escape(weights) }</strong>'
content = _('Data is weighted by the variable {}').format(bolded)
content = _('The data is weighted by the variable {}.').format(bolded)
else:
content = _('Data is unweighted')
self._html_pb.content = content
Expand Down

0 comments on commit 959640e

Please sign in to comment.