Selectize.js: i18n

Created on 5 Jun 2013  路  14Comments  路  Source: selectize/selectize.js

Suport for multiple languages.

Text to create new item is hardcoded english.

enhancement pull request welcome

Most helpful comment

If anyone is wondering how to change it as @brianreavis suggested, just do something like this:

$('.my-select').selectize({
  create: true,
  render: {
    option_create: function(data, escape) {
      var addString = 'Adicionar';
      return '<div class="create">' + addString + ' <strong>' + escape(data.input) + '</strong>&hellip;</div>';
    }
  }
});

All 14 comments

I think this would be an easy thing to address... might as well. In the meantime, you can always provide a render.option_create function in the settings to custom-render that dropdown item.

+1

+1

+1

+1

+1

If anyone is wondering how to change it as @brianreavis suggested, just do something like this:

$('.my-select').selectize({
  create: true,
  render: {
    option_create: function(data, escape) {
      var addString = 'Adicionar';
      return '<div class="create">' + addString + ' <strong>' + escape(data.input) + '</strong>&hellip;</div>';
    }
  }
});

As someone who's native tongue is French, I'd be inclined to accept a PR making this simpler. We could add an option allowing you to spectify a string (eg. addString: "Add %{name}") or a function addString: function(word){ I18n.t("selectize.add", word)}.

+1

I'll go even further in this, the function would be called with two params, function(word, key), allowing one to do:

addString: I18n.t

instead of:

addString: function(word, key){ I18n.t(word, key) }

Default: I18n.t if exists (or whatever is the JS convention for translation), or "Add %{name}".

or something automagic like that.

  • [x] Figure out strings that can be translated
  • [x] Figure out I18n conventions in JS and sensible defaults
  • [x] Begin writing tests
  • [ ] Finish writing tests
  • [ ] Write the code

Here's what I see:

describe("I18n", function(){
    describe("dictionary syntax", function(){
        var s = Selectize.init({
            dictionary: {
                addThis: "Ajouter %{elem}"
            }
        })

        expect(s.i18n('addThis', {elem: 'ceci'}).to.equal("Ajouter ceci")
    })

    describe("delegate to i18n library", function(){
        var I18n = {
            t: function(key, params) {
                return "Ajouter " + params.elem;
            }
        }

        var s = Selectize.init({
            i18n: I18n.t
        });

        expect(s.i18n('addThis', {elem: 'ceci'})).to.equal("Ajouter ceci")
    })

    describe("default i18n library", function(){
        var I18n = {
            t: function(key, params) {
                return "Ajouter " + params.elem;
            }
        }

        var s = Selectize.init({
            // i18n: default
        });

        expect(s.i18n('addThis', {elem: 'ceci'})).to.equal("Ajouter ceci")
    })
})

Libraries i18next, I18n-js and Polyglot all use syntax .t()

closing stale issues older than one year.
If this issue was closed in error please message the maintainers.
All issues must include a proper title, description, and examples.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbrooksuk picture jbrooksuk  路  42Comments

AndyBean picture AndyBean  路  15Comments

Saeven picture Saeven  路  15Comments

ghost picture ghost  路  60Comments

nesl247 picture nesl247  路  37Comments