From 4da24303341144ee43c018e6e24b0bc0074b5b50 Mon Sep 17 00:00:00 2001 From: krzysztofmadejski Date: Sun, 6 Nov 2016 17:13:12 +0000 Subject: [PATCH] #459 --- src/i18n/en.js | 7 ++- src/i18n/pl.js | 92 ++++++++++++++++++++++++-------------- src/i18n/view.i18n.js | 17 +++++-- src/view.flot.js | 41 +++++++++-------- src/view.grid.js | 3 +- src/view.map.js | 23 +++++----- src/view.multiview.js | 11 +++-- src/view.slickgrid.js | 27 ++++++++--- src/widget.fields.js | 2 + src/widget.filtereditor.js | 10 +++-- src/widget.queryeditor.js | 6 ++- src/widget.valuefilter.js | 4 +- test/view.i18n.test.js | 15 ++++--- 13 files changed, 168 insertions(+), 90 deletions(-) diff --git a/src/i18n/en.js b/src/i18n/en.js index baf523fe..d835c0c3 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -5,7 +5,12 @@ this.recline.View.translations = this.recline.View.translations || {}; this.recline.View.translations['en'] = { 'date_required': "A date is required, check field field-date-format", 'backend_error': 'There was an error querying the backend', - 'Distance_km': 'Distance (km)' + 'Distance_km': 'Distance (km)', + flot_Group_Column: 'Group Column (Axis 1)', + + map_mapping: 'Coordinates source', + map_mapping_lat_lon: 'Latitude / Longitude fields', + map_mapping_geojson: 'GeoJSON field' } // diff --git a/src/i18n/pl.js b/src/i18n/pl.js index e5bc1daa..fb7a0bb4 100644 --- a/src/i18n/pl.js +++ b/src/i18n/pl.js @@ -3,40 +3,66 @@ this.recline.View = this.recline.View || {}; this.recline.View.translations = this.recline.View.translations || {}; this.recline.View.translations['pl'] = { - 'Grid': 'Tabela', - 'Graph': 'Wykres', - 'Map': 'Mapa', - 'Timeline': 'Oś czasu', - 'Search_data': 'Wyszukaj w danych', - 'Go': 'Szukaj', - 'Add': 'Dodaj', - 'Add_row': 'Dodaj wiersz', - 'Delete_row': 'Usuń wiersz', - 'Update': 'Zaktualizuj', - 'Cancel': 'Anuluj', - 'Filters': 'Filtry', - 'Add_filter': 'Dodaj filtr', - 'Remove_this_filter': 'Usuń filtr', - 'Fields': 'Kolumny', - 'Field': 'Kolumna', - 'Filter_type': 'Typ filtra', - 'Value': 'Wartość', - 'Range': 'Zakres', - 'Geo_distance': 'Odległość', - 'From': 'Od', - 'To': 'Do', - 'Longitude': 'Długość geograficzna', - 'Latitude': 'Szerokość geograficzna', - 'Distance_km': 'Odległość (km)', - 'backend_error': 'Wystąpił błąd połączenia z serwerem', - 'Unknown': '???', - 'Edit_this_cell': 'Edytuj komórkę', - 'date_required': "Data jest wymagana: sprawdź kolumnę field-date-format", - 'Show_field': 'Pokaż kolumnę', - 'Force_fit_columns': 'Dopasuj kolumny do zawartości', - 'Expand_and_collapse': 'Rozwiń i zwiń', + Grid: 'Tabela', + Graph: 'Wykres', + Map: 'Mapa', + Timeline: 'Oś czasu', + Search_data: 'Wyszukaj w danych', + Search: 'Szukaj', + Add: 'Dodaj', + Add_row: 'Dodaj wiersz', + Delete_row: 'Usuń wiersz', + Reorder_row: 'Przesuń wiersz', + Update: 'Zaktualizuj', + Cancel: 'Anuluj', + Filters: 'Filtry', + Add_filter: 'Dodaj filtr', + Remove_this_filter: 'Usuń filtr', + Fields: 'Kolumny', + Field: 'Kolumna', + Filter_type: 'Typ filtra', + Value: 'Wartość', + Range: 'Zakres', + Geo_distance: 'Odległość', + From: 'Od', + To: 'Do', + Longitude: 'Długość geograficzna', + Latitude: 'Szerokość geograficzna', + Distance_km: 'Odległość (km)', + backend_error: 'Wystąpił błąd połączenia z serwerem', + Unknown: '???', + Edit_this_cell: 'Edytuj komórkę', + date_required: "Data jest wymagana: sprawdź kolumnę field-date-format", + Show_field: 'Pokaż kolumnę', + Force_fit_columns: 'Dopasuj kolumny do zawartości', + Expand_and_collapse: 'Rozwiń i zwiń', - 'num_records': '{recordCount} rekordów' + flot_info: '

Witamy!

\ +

Jakie kolumny powinny zostać narysowane na wykresie?

\ +

Wybierz je używając menu po prawej, a wykres pojawi się automatycznie.

', + Graph_Type: 'Typ wykresu', + Lines_and_Points: 'Linie z punktami', + Lines: 'Linie', + Points: 'Punkty', + Bars: 'Słupki poziome', + Columns: 'Słupki', + flot_Group_Column: 'Kolumna (Oś X)', + Please_choose: 'Proszę wybrać', + Remove: 'Usuń', + Series: 'Seria', + Axis_2: 'Oś Y', + Add_Series: 'Dodaj serię danych', + Save: 'Zapisz', + + map_mapping: 'Źródło koordynatów', + map_mapping_lat_lon: 'Szerokość i długość geo.', + map_mapping_geojson: 'Jedna kolumna typu GeoJSON', + Latitude_field: 'Kolumna szerokości geo. (WGS84)', + Longitude_field: 'Kolumna długości geo. (WGS84)', + Auto_zoom_to_features: 'Kadruj, aby pokazać wszytkie punkty', + Cluster_markers: 'Łącz pobliskie punkty w grupy', + + num_records: '{recordCount} rekordów' } // diff --git a/src/i18n/view.i18n.js b/src/i18n/view.i18n.js index 065850e5..d3a88717 100644 --- a/src/i18n/view.i18n.js +++ b/src/i18n/view.i18n.js @@ -8,8 +8,10 @@ Backbone.I18nView = Backbone.View.extend({ defaultLocale: 'en', locale: 'en', - initializeI18n: function(locale) { - this.locale = locale; + initializeI18n: function(locale, appHardcodedLocale) { + this.defaultLocale = appHardcodedLocale || 'en'; + this.locale = locale || this.defaultLocale; + // TODO implement cache //memoizeFormatConstructor(Intl.NumberFormat).getNumberFormat(); }, @@ -30,7 +32,14 @@ Backbone.I18nView = Backbone.View.extend({ } msg = defaultMessage; } - if (msg == null) { msg = key; } // TODO w domyślnym locale automatycznie usuwaj podkreślenia + if (msg == null) { + msg = key; + if (this.locale === this.defaultLocale) { + // no need to define lang entry for short sentences, just use underscores as spaces + msg = msg.replace(/_/g, ' '); + } + + } // TODO i18n documentation @@ -73,4 +82,4 @@ Backbone.I18nView = Backbone.View.extend({ 't': formatter, }; }, -}); +}); \ No newline at end of file diff --git a/src/view.flot.js b/src/view.flot.js index 0197b874..38616f51 100644 --- a/src/view.flot.js +++ b/src/view.flot.js @@ -22,14 +22,14 @@ this.recline.View = this.recline.View || {}; // // NB: should *not* provide an el argument to the view but must let the view // generate the element itself (you can then append view.el to the DOM. -my.Flot = Backbone.View.extend({ +my.Flot = Backbone.I18nView.extend({ template: ' \
\
\
\ -

Hey there!

\ + {{#t.flot_info}}

Hey there!

\

There\'s no graph here yet because we don\'t know what fields you\'d like to see plotted.

\ -

Please tell us by using the menu on the right and a graph will automatically appear.

\ +

Please tell us by using the menu on the right and a graph will automatically appear.

{{/t.flot_info}} \
\
\
\ @@ -38,6 +38,7 @@ my.Flot = Backbone.View.extend({ initialize: function(options) { var self = this; this.graphColors = ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"]; + this.initializeI18n(options.locale); _.bindAll(this, 'render', 'redraw', '_toolTip', '_xaxisLabel'); this.needToRedraw = false; @@ -56,7 +57,8 @@ my.Flot = Backbone.View.extend({ this.previousTooltipPoint = {x: null, y: null}; this.editor = new my.FlotControls({ model: this.model, - state: this.state.toJSON() + state: this.state.toJSON(), + locale: this.locale }); this.listenTo(this.editor.state, 'change', function() { self.state.set(self.editor.state.toJSON()); @@ -67,7 +69,7 @@ my.Flot = Backbone.View.extend({ render: function() { var self = this; - var tmplData = this.model.toTemplateJSON(); + var tmplData = _.extend(this.model.toTemplateJSON(), this.MustacheFormatter()); var htmls = Mustache.render(this.template, tmplData); this.$el.html(htmls); this.$graph = this.$el.find('.panel.graph'); @@ -362,29 +364,29 @@ my.Flot = Backbone.View.extend({ } }); -my.FlotControls = Backbone.View.extend({ +my.FlotControls = Backbone.I18nView.extend({ className: "editor", template: ' \
\
\
\
\ - \ + \
\ \
\
\
\ - \ + \
\ \
\ \ @@ -407,8 +409,8 @@ my.FlotControls = Backbone.View.extend({ templateSeriesEditor: ' \
\
\ -
\ - \ + \ \ ', @@ -27,9 +27,11 @@ my.QueryEditor = Backbone.I18nView.extend({ 'submit form': 'onFormSubmit' }, - initialize: function() { + initialize: function(options = {}) { _.bindAll(this, 'render'); this.listenTo(this.model, 'change', this.render); + this.initializeI18n(options.locale); + this.render(); }, onFormSubmit: function(e) { diff --git a/src/widget.valuefilter.js b/src/widget.valuefilter.js index f29e6c32..60cdd9b8 100644 --- a/src/widget.valuefilter.js +++ b/src/widget.valuefilter.js @@ -50,10 +50,12 @@ my.ValueFilter = Backbone.I18nView.extend({ 'submit form.js-edit': 'onTermFiltersUpdate', 'submit form.js-add': 'onAddFilter' }, - initialize: function() { + initialize: function(options = {}) { _.bindAll(this, 'render'); this.listenTo(this.model.fields, 'all', this.render); this.listenTo(this.model.queryState, 'change change:filters:new-blank', this.render); + this.initializeI18n(options.locale); + this.render(); }, render: function() { diff --git a/test/view.i18n.test.js b/test/view.i18n.test.js index 669a13e7..52adfce5 100644 --- a/test/view.i18n.test.js +++ b/test/view.i18n.test.js @@ -129,11 +129,16 @@ test('translate complex key custom locale custom count', function () { locale: 'pl' }); -// todo custom count string - equal(view.t('some_msg', {records: 0}, '{{records}} records'), 'brak rekordów'); - equal(view.t('some_msg', {records: 1}, '{{records}} records'), '1 rekord'); - equal(view.t('some_msg', {records: 3}, '{{records}} records'), '3 rekordy'); - equal(view.t('some_msg', {records: 5}, '{{records}} records'), '5 rekordów'); + recline.View.translations['pl']['codeforall'] = '{records, plural, ' + + '=0 {brak zdjęć}' + + '=1 {{records} zdjęcie}' + + 'few {{records} zdjęcia}' + + 'other {{records} zdjęć}}'; + + equal(view.t('codeforall', {records: 0}), 'brak zdjęć'); + equal(view.t('codeforall', {records: 1}), '1 zdjęcie'); + equal(view.t('codeforall', {records: 3}), '3 zdjęcia'); + equal(view.t('codeforall', {records: 5}), '5 zdjęć'); });