Sep 2009 11

Biaxin For Strep

About



jQuery.i18n.properties is a lightweight jQuery Biaxin for strep, plugin for providing internationalization to javascript from '.properties' files, just like in Java Resource Bundles. It loads and parses resource bundles (.properties) based on provided language and country codes (ISO-639 and ISO-3166) or language reported by browser.


Resource bundles are '.properties' files containing locale specific key-value pairs. The use of '.properties' files for translation is specially useful when sharing i18n files between Java and JavaScript projects, biaxin xl pak directions. This plugin loads the default file (eg, Biaxin xl 500mg, Messages.properties) first and then locale specific files (Messages_pt.properties, then Messages_pt_PT.properties), so that a default value is always available when there is no translation provided, biaxin for strep throat. Translation keys will be available to developer as javascript variables/functions (functions, Biaxin for strep, if translated value contains substitutions (eg, {0}) or as a map.


This plugin was inspired on the Localisation assistance for jQuery from Keith Wood, and is made available under a dual license (GPL and MIT).


Features





  • Use Java standard '.properties' files for translations

  • Use standard ISO-639 for language code and ISO-3166 for country code

  • Sequential loading of resource bundles from base language to user-specified/browser-specified so there is always a default value for an untranslated string (eg: msg.properties, order biaxin, msg_pt.properties, Biaxin xl 500mg clarithromycin, msg_pt_PT.properties)

  • Use browser reported language if no language was specified

  • Placeholder substitution in resource bundle strings (eg, msg_hello = Hello {0}!!)

  • Suport for namespaces in keys (eg, com.company.msgs.hello = Hello!)

  • Support for multi-line property values

  • Resource bundle keys available as Javascript vars/functions or as a map



Example



Take as an example the following Messages.properties, biaxin for sale, Messages_pt.properties and Messages_pt_PT.properties:


Messages.properties


# This line is ignored by the plugin
msg_hello = Hello
msg_world = World
msg_complex = Good morning {0}.

Messages_pt.properties


# We only provide a translation for the 'msg_hello' key
msg_hello = Bom dia

Messages_pt_PT.properties


# We only provide a translation for the 'msg_hello' key
msg_hello = Olá


Now, suppose these files are located on the 'bundle/' folder, biaxin for strep. Buy biaxin online, One can invoke the plugin like below:

// This will initialize the plugin
// and show two dialog boxes: one with the text "Olá World"
// and other with the text "Good morning John!"
jQuery.i18n.properties({
name:'Messages',
path:'bundle/',
mode:'both', prescription for ear infection,
language:'pt_PT', Medication for ear infection, callback: function() {
// We specified mode: 'both' so translated values will be
// available as JS vars/functions and as a map

// Accessing a simple value through the map
jQuery.i18n.prop('msg_hello');
// Accessing a value with placeholders through the map
jQuery.i18n.prop('msg_complex', ['John']);

// Accessing a simple value through a JS variable
alert(msg_hello +' '+ msg_world);
// Accessing a value with placeholders through a JS function
alert(msg_complex('John'));
}
});

This will initialize the plugin (loading bundle files and parsing them) and show a dialog box with the text "Olá World" and other with "Good morning John!". The english word "World" is shown because we didn't provide a translation for the msg_world key, biaxin for strep. Also notice that keys are available as a map and also as javascript variables (for simple strings) and javascript functions (for strings with placeholders for substitution).


Usage


Options
























OptionDescriptionNotes
namePartial name (or names) of files representing resource bundles (eg, Prescription for ear infection, 'Messages' or ['Msg1','Msg2'])Required
String or String[]
languageISO-639 Language code and, optionally, buy biaxin online, ISO-3166 country code (eg, Order biaxin, 'en', 'en_US', 'pt_PT'), biaxin for ear infections. If not specified, language reported by the browser will be used instead.Optional
String
pathPath to directory that contains '.properties' files to load.Optional
String
modeOption to have resource bundle keys available as Javascript vars/functions OR as a map. The 'map' option is mandatory if your bundle keys contain Javascript Reserved Words Biaxin for strep, . Possible options: 'vars' (default), 'map' or 'both'Optional
String
callbackCallback function to be called uppon script execution completion.Optional
function()

Including and invoking the plugin



  1. Load the script:




  2. Initialize the plugin (minimal usage, will use language reported by browser), and access a translated value (assuming a key named 'org.somekey' exists):

    jQuery.i18n.properties({
    name: 'Messages',
    callback: function(){ alert( org.somekey ); }
    });


Demo


See a small demonstration


Download



1.0.8  [2010-07-09]


Change Log



1.0.8  [2010-07-09]


  • Fixed IE bug caused by the MS buggy implementation of String.split() method


1.0.7  [2010-06-09]


  • Added support for multi-line properties

  • Prevent browser caching of old property files


1.0.6  [2010-03-28]


  • Fixed checkKeyNamespace issue (FF only)

  • Fixed issue that truncated values when containing '=' symbol

  • Added demo page


1.0.4  [2009-12-29]


  • When using the map approach to retrieve bundle values, unicode chars may not be properly unescaped


1.0.3  [2009-10-06]


  • When using the map approach to retrieve bundle values, if there's no value for a specified key, key is returned (previously, null was returned)

  • Fixed lot of errors accordingly to JSLint


1.0.2  [2009-09-18]


  • Option to have resource bundle keys available as Javascript vars/functions AND/OR as a map. The later is mandatory if your bundle keys contain Javascript reserved words


1.0.1  [2009-09-14]


Known issues




  • Cross-site requests not allowed (see Same Origin policy).

  • Local file requests (file://) may fail in some browsers (Chrome Issue 40787)

  • Having HTML elements with IDs equal to key values in .properties files will fail on some browsers (IE, Chrome) when values are not accessed through jQuery.i18n.prop() method.
    Example:


    ola

    # on .properties file:
    test123 = qwerty

    Executing "alert(test123);" will output the div object with id "ola" and not the "qwerty" string.

.

Similar posts: Biaxin xl 500mg. Medication for ear infection. Biaxin xl pak. Order biaxin. Biaxin xl 500 mg. Buy biaxin online.
Trackbacks from: Biaxin for strep. Biaxin for strep. Biaxin for strep. Biaxin for strep. Biaxin for strep. Biaxin for strep.

  • GO BACK | HOME PAGE
  • SHARE/SAVE | ARTICLE
  1. nfgrilo (Nuno Fernandes)

    Released jQuery plugin for I18N from .properties files, with support for placeholder subsititutions: http://codingwithcoffee.com/?p=272 #fb

  2. Lovemore Nalube

    This is fantastic work! I am trying it out in Sakai’s Course Evaluation Tool @ http://jira.sakaiproject.org/browse/EVALSYS-795

  3. Lovemore Nalube

    Hi, I’ve had little success implementing this so far. The following issue up:

    The path bundle/messages.properties is not made available for direct access by tomcat restrictions. Hence only an RSF error page is called with no translation strings in it. Hence this parse error is thrown by jquery.i18n:

    syntax error typeof <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 == "undefined"

  4. Nuno

    Hi Lovemore!

    One approach you may try is to use the ’maven-resources-plugin’ to copy your bundle files at compile time to a tool webapp folder (accessible location by the webserver).

    In the base pom.xml of the tool:
      <build>
      <pluginManagement> 
        <plugins> 
          <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-resources-plugin</artifactId> 
            <version>2.4</version> 
          </plugin> 
        </plugins> 
      </pluginManagement> 
      </build>

    In the tool/pom.xml:
      <build>
        <!– …….. –>
        <plugin>
    <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-resources-plugin</artifactId> 
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>process-resources</phase>
                <goals><goal>resources</goal></goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/${project.build.finalName}/bundle</outputDirectory>
                  <resources>          
                    <resource>
    <!– Change THIS to get to you actual folder containing the .properties files –>           <directory>${basedir}/../bundle/src/resources</directory>
                    </resource>
                  </resources>              
                </configuration>            
              </execution>
            </executions>
          </plugin>
          
        </plugins>
        
      </build>

    Hope this helps!
    Please let me know if it solved your issue!

    Nuno

  5. Lovemore Nalube

    Hey that worked! JS can access the properties file now. But there’s a bug with parsing the file:

    not well-formed:
    [Break on this error] # Application messages file – Sakai Evaluation System -AZ

    the comments within the properties file prefixed with # throw this exception and the plugin just gives up.

    Any thoughts?

  6. Nuno

    Hi Lovemore!
    I have already seen that message – is it from Firebug 1.4? I have a lot of things (like JS templates) that firebug reports as errors but everything is working fine. Before considering this a bug, can you please test this (replacing with the correct values):

    jQuery.i18n.properties({name:’messages’, path:’bundle/’, language:’en’, callback: function() {
    // replace by a parsed key from the bundle
    alert(msg_some_key);
    }});

    If that doesn’t work, can you please send me your .properties file so I can test it locally? Just send me using the contact form on the top of this page :)

    Thanks,
    Nuno

  7. Nuno

    Not sure if I have already update Firebug meanhile (now have 1.4.2) because similar error have gone from my console. Testing a .properties file with that comment line works fine for me…

    Nuno

  8. Lovemore Nalube

    Here is the properties file: https://source.sakaiproject.org/contrib/evaluation/trunk/tool/src/java/org/sakaiproject/evaluation/tool/bundle/messages.properties

    The callback function does not execute.
    Firebug is 1.4.2

    Thanks
    Lovemore

  9. Nuno

    I found the issue: since the bundle keys are available as javascript variables/functions, some do fail because Javascript reserved words cannot be used!

    http://javascript.about.com/library/blreserved.htm

    I will modify the plugin to have an option of accessing the bundle keys through an array (map) and will add a comment when ready!

    Nuno

  10. Nuno

    Hi Lovemore!

    In your case, since Javascript reserved words are being used inside the .properties file (delete), you must download the 1.0.2 version and specify the option mode:’map’. Example:

    jQuery.i18n.properties({name:’messages’, path:’bundle/’, language:’en’, mode:’map’, callback: function() {
    // replace by a parsed key from the bundle
    alert( jQuery.i18n.prop(‘msg_some_key’) );
    }});

    Hope this helps,
    Nuno

  11. Lovemore Nalube

    Hi Nuno :)

    A while back I had an idea of a twist to your idea. I’ve detailed it here: http://blogs.uct.ac.za/blog/lovemores-world/2009/09/28/consuming-a-sakai-java-messages-resource-bundle-in-javascript-with-fluid-i8n

    Would love to know what you think. My code is running in the Sakai Course Evaluations tool :)

  12. shotchen

    please try this:
    layout.close_pane = \u5173\u95ED
    alert(jQuery.i18n.prop(“layout.close_pane”));
    alert(layout.close_pane);

    first alert is show \u5173\u95ED and second alert will show 关闭 ,why?

  13. Jason Shao

    I dig this – though I wish there was an easier way to over-ride w/a db as a message source, to support easy GUI customization of bundles w/o writing to files.

    Dynamically generate the .properties files using a servlet that did dynamic db overlay ontop of the underlying file? (we use something similar for portlets – we standardized on tags to make db slightly easier as a message source.

  14. Nuno

    Hi Jason!
    If what you’re trying to achieve is some kind of dynamic generation of bundles (server-side) in Sakai, one possible approach (and alternative to this plugin) is to use EntityBroker RESTfull capability to return either a ResourceLoader object or a map {key,translation}. This way, you can simply query server through ajax and restfull urls to retrieve the results as a Javascript map (JSON)! Entitybroker return results encoded in JSON automatically.
    Is this your objective?

    Thank you for your thoughts,
    Nuno

  15. Nuno

    Hi Shotchen!

    Thank you for reporting the issue! I have just updated the plugin to fix it (1.0.4). Thank you very much, Nuno

  16. Micah Sutton

    I have encountered a problem with using multiple namespaced properties. In the function checkKeyNamespace, for a reason I am unable to deduce, regDot.test returns false!

    Example .properties file
    one.two.three = blah
    one.two.four = blah1
    one.three.three = blah2
    one.four.three = blah3
    one.five.three = blah4

    Result of the regex test
    one.two.three true /\./g {}
    one.two.four true /\./g {}
    one.three.three true /\./g {}
    one.four.three false /\./g {} <—-!!!!
    one.five.three true /\./g {}

    I did fix this problem by removing the regex global option. But as to why that should cause it to fail is beyond me!

    var regDot = /\./; seem to work fine…

  17. Micah Sutton

    This appears to only affect firefox (I have 3.5.7, and tested with 3.6 as well) so it could be a firefox bug.

  18. Nuno

    Hi Micah!
    Thank you very much for your feedback – while this isn’t fixed, you may try to use the “map” approach instead. Ironically, I am (since 2 days) trying to fix a stupid bug only occurring in FF3.5 and FF3.6…..

    Thanks,
    Nuno

  19. LightningX (Lightning)

    Javaのプロパティっぽく使えるjqueryのプラグイン。http://codingwithcoffee.com/?p=272

  20. Nuno Brites

    Hi Nuno,

    First of all I would like to thank you for sharing your code.

    I’ve found a small bug, for example, if you want to store an url in your *.properties file, something like

    myURL = http://localhost/webapp/servletName?solution=solutionName

  21. Nuno Brites

    (Something went wrong with my post previous, heres the rest of it…). You want be able to parse the line since you split the pair by the character “=” and it will split the pair in more than one value.
    I found a simple solution by changing your code line “var pair = parameters[i].split(‘=’);” into “var pair = parameters[i].split(‘=’,2);”.
    Cheers e cumprimentos portugueses

  22. Nuno

    Hi Nuno!

    Thank you for using and providing feedback :)
    I will be fixing this (incorporating your bugfix) and some other minor bugs early next week!

    Obrigado e “happy codding (with coffee:))”!
    Nuno

  23. Pablo Garaizar

    Hi Nunos (Fernandes and Brites ;) )!

    IMHO Nunu Brites’ solution is not very robust because it simply truncates strings from the 2nd appearance of ‘=’.

    Taking into account that I needed some HTML embeded in localised strings (e.g. msg_link = Come to my site), here is my bugfix:

    Change:

    var value=pair.length==1?”":pair[1];

    To:

    var all=pair[1];for(s=2;s<pair.length;s ){all ='=' pair[s]};

    It works for me, but maybe further testing must be done ;-)

  24. Pablo Garaizar

    All plus symbols gone, but I think it’s still undestandable O:-)

  25. Pablo Garaizar

    Another suggestion: allow local Messages.properties file load, in a similar way to http://cssgallery.info/mootools-ajax-request-for-local-files/

  26. Nuno

    Nuno, Pablo and Micah,

    Thank you for reporting issues and providing fixes and examples – I have updated the plugin with all these fixes!

    Thank you all,
    Nuno

  27. Nuno

    Pablo,

    I only saw your last comment after releasing 1.0.6. However, I don’t understand your suggestion (as you can load local and remote files with the plugin)… can you please elaborate on your suggestion?!

    Thank you!
    Nuno

  28. Pablo Garaizar

    Hi Nuno!

    Thanks a lot for the new release ;-)

    My suggestion: instead of/in addition to your AJAX approach to load messages files, it could be great to have other loading methods that works in every browser (AJAX file loading in local seems to be a security policy violation in Google Chrome and other browsers).

    I fixed this issue creating an script tag in the DOM, and appending it to the head of the document:

    document.createElement(’script’) document.getElementsByTagName(“head”).item(0).appendChild(script);

    This works fine with every browser I’ve tested (Firefox 3.5/3.6, IE 7/8, Google Chrome 5.0.x, Epiphany, Seamonkey/Iceweasel, etc.).

    Maybe this method should be added to the current one :-)

  29. Nuno

    Hi Pablo!!!

    Thank you very much for your comment and suggestion!
    Could you please send me your code addition so I can look at it and include it on the release?

    Thank you and happy coding :)
    Nuno

  30. Dinuka

    Hi,

    First of all thx for this amazing plugin. I have a small query. Say if i want to use this as the fmt tag. Can i do the rendering of the locale based text when the page is rendered? Because at the moment i hv to replace the text after dom load. Is there any way?

    Thanks in advance,
    Dinuka

  31. Nuno

    Hi Dinuka!
    Thank your for your thoughts! If I understand correctly, you’re first rendering server-side (through JSP) and then want to update the page on the client-side (through JS/Ajax). Is this the case? If so, you may need to store the user locale on the page (eg, in an hidden field) when rendering server-side and then, at client-side, initialize this plugin using that locale!

    Hope it helps,
    Nuno

  32. dinuka

    Hi Nuno,

    Thx for the reply. Actually what i wanted was to render the locale based text on page render. As in like the following;

  33. dinuk

    Hi Nuno,
    Sorry for the above post.Pls disregard it.
    Actually what i wanted was to render the locale based text on page render. As in like the following;

    and one other thing was that the plugin was not working in IE 6. Is that a known issue? is there any work around for it?

    Thanks again for the help

    Dinuka

  34. Dinuka

    Hi Nuno,

    Sorry this does work on IE 6 but when you use the parameterized text you can only use the form where it uses as such;

    jQuery.i18n.prop(‘msg_complex’, ['John']);

    The following does not work in IE 6;
    alert(msg_complex(‘John’));

    Regards,
    Dinuka

  35. BenHur

    It seems to me that if the message properties file are located to another host, this script fails. Can anyone confirm this?

  36. Nuno

    Hi,
    I have not tested this (serving the bundle files from other host), but looking at the code it should equally work. The ‘path’ parameter is passed (without processing) to ‘url’ parameter of jQuery.ajax function.
    Are you providing a full url (to the folder, not a single bundle file)? Can you check with Firefox Firebug extension what’s happening?

    Thanks,
    Nuno

  37. BenHur

    It does not work because inside the js script there is an ajax call to read the messages files. Well, as you probably know, Cross-Domain XMLHttpRequest Calls are forbidden in ajax due to the browsers restrictions.

  38. Nuno

    I can confirm this is working: I have tested from one host loading bundles from other host (the later with SSL) and it’s working as expected.
    Just remember to specify the path parameter as follows, with the slash at the end:

    (…)
    path:’http://HOST/other_dir/bundle/’,
    name:’msg’
    (…)

    This will load bundle files like:
    http://HOST/other_dir/bundle/msg.properties
    http://HOST/other_dir/bundle/msg_fr_CA.properties

    Hope it helps,
    Nuno

  39. Nuno

    Hum… you’re right. Just wondering why this worked with me (maybe because I’m using Google Chrome on dev channel).

  40. BenHur

    Can you please try this?
    name:’up_mail_messages’,
    path:’https://static.unifiedpost.com/apps/myup/customer/upmail/upmail_messages/’

    I’m searching for the value of: up.mail.test
    but it does not find it…

  41. Nuno

    It’s working for me. You may be trying to access the property before it has been actually made available. Please try using the ‘callback’ param:

    jQuery.i18n.properties({
    name: ‘up_mail_messages’,
    path: ‘https://static.unifiedpost.com/apps/myup/customer/upmail/upmail_messages/’,
    mode:’both’,
    callback: function() {
    alert(up.mail.test);
    alert(jQuery.i18n.prop(‘up.mail.test’));
    }
    });

  42. BenHur

    Hi,
    Tested with your code wrapped in a method named loadMessage(). This method is called like:

    jQuery(document).ready(loadMessage);

    The first alert fails so i comment it to be albe to run the second alert which prints out: [up.mail.test]

    Extremely strange…

  43. Nuno

    Don’t you have any errors in the browser logs/console?
    (Just a note that a comma ‘,’ is missing on the above example, right after the path).

  44. BenHur

    yes, say the missing comma and corrected. no result yet.

    With firebug, i’ve noticed that, when path is a host it does not enter in 114 line of the code within your js source code:

    $.ajax({
    109 url: filename,
    110 async: false,
    111 contentType: “text/plain;charset=UTF-8″,
    112 dataType: ‘text’,
    113 success: function(data, status) {
    114 var parsed = ”;

    }

    can you check this please?

    When the paths is a local file that line is succesfully processed.

  45. Nuno

    I tested and, no, it doesn’t work on FF. It’s the Cross-Domain XMLHttpRequest issue you referred. It works on Safari (and should work on Chrome also).

    These security policies can be very annoying… :(

  46. Pablo Garaizar

    Nuno, sorry for not responding. I’ve been very busy these days O:-)

    I’ve developed one example of the offline-safe method of loading local properties files here: http://www.labpsico.deusto.es/wp-content/uploads/2010/04/labprime-1.2.0.zip

    As you can see, the function translateApplication() at js/lib.js does the trick ;-)

  47. Sameed

    I am trying to use the plugin. In a small example I include this plugin in another .js file and then call the function from .html file. I am doing this to simulate for my actual work. But I get jQuery is undefined. Any help is appreciated.

    function include(file)
    {
    alert(file);
    var script = document.createElement(’script’);
    script.src = file;
    script.type = ‘text/javascript’;
    script.defer = true;
    document.getElementsByTagName(‘head’).item(0).appendChild(script);
    }

    function function3(){
    include(‘js/jquery.i18n.properties.js’);
    jQuery.i18n.properties({name: ‘Messages’});
    alert(

  48. Nuno

    Hi!

    @Sameed,
    Please make sure the jQuery framework is loaded before the jQuery.i18n.properties plugin. You see the source code of the demo page for help (http://codingwithcoffee.com/files/trunk/index.html) although this is page code is more complex than needed.

    @Pablo,
    I will look at your code ASAP. Maybe I could use something similar to have offline-safe method :)

    Thanks,
    Nuno

  49. Timo Kinnunen

    Hi, it doesn’t appear that the plugin handles correctly long property values that have been split to multiple lines using the backslash character, like this:

    key=Hello\n\
    \n\
    World long value here

Leave a Reply