Coder Social home page Coder Social logo

Comments (3)

santhoshtr avatar santhoshtr commented on May 21, 2024 1

In most of the usecases, the resource files(message json) is at server and it takes a while to get loaded at client. It is not recommended to block the code execution by using synchronous message file loading.

Following is a convenient wrapper around $.fn.i18n that take care of message loading as well.

        $.fn.i18nText = function ( key, params ) {
            var i18n = $.i18n(),
                $element = $( this );
            i18n.load( 'i18n/en.json', 'en' ).done( function () {
                if ( $element.data( 'i18n' ) ) {
                    $element.i18n();
                } else {
                    $element.text( $.i18n( key, params ) );
                }
            } );
            return $element;
        }
        $( document ).ready( function ( $ ) {
            $( 'span' ).i18nText( 'key-one', 3 );
        } )

I hope that helps

from jquery.i18n.

santhoshtr avatar santhoshtr commented on May 21, 2024

Now that I wrote this, I am thinking why can't this the jquery.i18n have the above feature? :). I will investigate it as an enhancement. Thanks

from jquery.i18n.

toddca avatar toddca commented on May 21, 2024

Not sure how I get around blocking for a resource, when my page loads I have script which sometimes runs which needs to show the user a message (error/warning, etc) this script calls into my wrapper to load the string resources for the dismiss buttons on the dialog being created. If I show the message before the resources are fully loaded I get the key of the message rather than the message string.

from jquery.i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.