Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:29:30+00:00 2026-06-13T08:29:30+00:00

Like most people, I use a bunch of jquery plugins on my website. From

  • 0

Like most people, I use a bunch of jquery plugins on my website. From Twitter bootstrap to jquery ui datepicker and so on.

But I need my website to be multilingual, so I created a general language file called english.js , and in that file I want to declare some of the defaults from plugins as well as other language variables.

The problem is that all these plugins have varying structures to declare defaults. I saw a couple of questions already ( jquery – setting plugin defaults?, Globally defining jQuery plugin parameters , jQuery plugin defaults , …). But they are not clear.

STRUCTURE 1

$.fn.ajaxStatus = function (params)
{
    var settings = $.extend(
            {
                defaultLoadingText :"Loading...",
                defaultSavingText  :"Saving...",
                defaultDoneText    :"Done",
                defaultRedirectText:"Redirecting...",
                defaultErrorText   :"Oops! Our bad, something wrong.";
            },$.fn.ajaxStatus.defaults,
            params),
});

STRUCTURE 2

   jQuery.fn.extend({
        shrinker:function (options) {
            var opts = $.extend({
                "moreText":"Read more", 
                "lessText":"hide",
            }, $.fn.shrinker.defaults, options);
   });

THE QUESTION

Without modifying the plugin, is it possible to assign some defaults for the function that will be used every time I use the plugin?
How can I define the language defaults in an external file?

Right now, I have this in my language file, but it feels wrong, is this how you do it?

if ($.fn.ajaxStatus !== undefined) {
    $.fn.ajaxStatus.defaults =
    {
        defaultLoadingText :"Loading2...",
        defaultSavingText  :"Saving2...",
        defaultDoneText    :"Done2",
        defaultRedirectText:"Redirecting2...",
        defaultErrorText   :"Oops! Our bad, something wrong"
    };
}

Thanks in advance for you help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:29:32+00:00Added an answer on June 13, 2026 at 8:29 am

    I could see doing it in one object, like this:

    var en = {
        defaultLoadingText: "Loading...",
        defaultSavingText: "Saving...",
        defaultDoneText: "Done",
        defaultRedirectText: "Redirecting...",
        defaultErrorText: "Oops! Our bad, something wrong.";
        moreText: "Read more", 
        lessText: "hide"
    };
    

    Assuming there’s no overlap in option names between plugins, you could just start your plugins with:

    $('').ajaxStatus(en);
    $('').shrinker(en);
    

    Most plugins take in an options object and ignore the extra properties. If you have some other options you want to pass to a particular plugin, you just use $.extend():

    $('').ajaxStatus($.extend({}, { success: function () {} }, en));
    

    If you really wanted to keep the plugin options separate, just create another level:

    var en = {
        ajaxStatus: {
            defaultLoadingText: "Loading...",
            defaultSavingText: "Saving...",
            defaultDoneText: "Done",
            defaultRedirectText: "Redirecting...",
            defaultErrorText: "Oops! Our bad, something wrong.";
        },
        shrinker: {
            moreText: "Read more", 
            lessText: "hide"
        }
    };
    

    Then:

    $('').ajaxStatus(en.ajaxStatus);
    $('').shrinker(en.shrinker);
    

    Finally, you could get fancy and make it easier to get different languages by storing them all in one multi-layered object:

    var localizedOptions = {
        'en-US': {
            ajaxStatus: {
                defaultLoadingText: "Loading...",
                defaultSavingText: "Saving...",
                defaultDoneText: "Done",
                defaultRedirectText: "Redirecting...",
                defaultErrorText: "Oops! Our bad, something wrong.";
            },
            shrinker: {
                moreText: "Read more", 
                lessText: "hide"
            }
        },
        'es-ES': {
            ajaxStatus: {
                defaultLoadingText: "Cargar...",
                defaultSavingText: "Guardar...",
                defaultDoneText: "Terminado",
                defaultRedirectText: "Redirigir...",
                defaultErrorText: "¡Ay! Nuestra algo malo, malo.";
            },
            shrinker: {
                moreText: "Leer más", 
                lessText: "esconder"
            }
        } // ... etc.
    };
    

    And

    $('').ajaxStatus(localizedOptions[navigator.language || navigator.userLanguage].ajaxStatus);
    

    I must admit I haven’t used something like this myself, because I usually get language files in the form of a resource file. In that case, I’ll just output a single collection of key/value pairs via server-side logic and manually set the appropriate plugin properties.

    In ASP.NET MVC:

    <script>
    var Resources = {};
    @foreach (var kvp in ViewBag.Resources) {
    Resources['@kvp.Key'] = "@kvp.Value";
    }
    </script>
    

    This would output a different set, depending on the page I’m on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to build a feature like most of the banks use. Where.. if
Like most people I use SWFObject to embed Flash (swf) files to my Web
Most people use pointers like this... if ( p != NULL ) { DoWhateverWithP();
We have a basic service that some people use but most people want their
Like most people, I work on a data-driven object-oriented business application. I use a
It seems like most people use MySQL together with PHP. I've used H2 and
It looks like this template tag works like a charm for most people: http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/
What's the most most ruby-like way of converting from an Array like [:one, 1,
Like most people new to Git, I've had my share of confusion trying to
Like most people, I learnt C++ after C. I learnt C++ because it was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.