Datatables 3: Internationalization

Datatables 3: Internationalization

tacman1123tacman1123 Posts: 235Questions: 52Answers: 1

Perhaps with dynamic imports it's less of an issue, but do you think you'll be reviewing language packs?

Answers

  • allanallan Posts: 65,740Questions: 1Answers: 10,934 Site admin

    Updating the plugins is one of my outstanding tasks for DataTables 3, however the language files should work as is. Is there something specific that you are looking for me to review?

    Allan

  • tacman1123tacman1123 Posts: 235Questions: 52Answers: 1
    edited April 26

    If I know the local (e.g. from the request, or a user property) I want it to be easy load the language back based on that. I think right now I have to load the language pack for each specific language.

    Perhaps this is changed with the await javascript. My controller has

    import enLanguage from "datatables.net-plugins/i18n/en-GB.mjs";
    import esLanguage from "datatables.net-plugins/i18n/es-ES.mjs";
    import deLanguage from "datatables.net-plugins/i18n/de-DE.mjs";
    

    When what I want is to simply pass the locale and have the library use it and not do this.

        let language = enLanguage;
        if (this.locale === "en") {
          language = enLanguage;
        } else if (this.locale === "es") {
          language = esLanguage;
        } else if (this.locale === "de") {
          language = deLanguage;
         
          }else if(this.locale == 'uk') {
               language = ukLanguage;
           }else if(this.locale == 'hu') {
               language = huLanguage;
           }else if(this.locale == 'hi') {
               language = hilanguage;
        }
    
    

    Which I'm sure can be optimized, but still feels like there must be a better solution.

  • WernfriedWernfried Posts: 28Questions: 6Answers: 0
    edited April 26

    I am not the super expert in Javascript but as far as I know, when you do import ... from .... then the module is only loaded at the moment when it is really used.

    Thus your if () else if .... construct is rather pointless.

  • allanallan Posts: 65,740Questions: 1Answers: 10,934 Site admin

    when you do import ... from .... then the module is only loaded at the moment when it is really used.

    Kind of. It depends what you mean by loaded. In this case, that looks like it is code that will be bundled, so all of the language data would need to be sent to the client-side, where it can then resolve the if condition for which one is to be used. So in this case, the if condition is needed.

    There is dynamic import and all of the current browsers do support that, so that might be one option, although I've found client-side imports (when using import maps) to be quite frustrating (perhaps things have improved since then...).

    Perhaps a nice solution would be to have a small server which can resolve the request of a locale and then serve the language file that is needed. You simply load (or import) a single script and it would add the call to get the required language file. I quite like that idea and will look into that in future.

    Allan

Sign In or Register to comment.