Skip to content

Commit

Permalink
default culture is named default
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinitiesLoop committed Jun 8, 2010
1 parent d074e1f commit 72df551
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -52,7 +52,7 @@ A mapping of culture code to that culture. For example, jQuery.cultures.fr is an
<p> <p>
This is set to the culture currently being used. This serves as the default culture if no culture is specified on the various parsing and formatting functions. For example, to change the current culture, set it to one of the available cultures: This is set to the culture currently being used. This serves as the default culture if no culture is specified on the various parsing and formatting functions. For example, to change the current culture, set it to one of the available cultures:
<pre> <pre>
jQuery.culture = jQuery.cultures["FR-fr"]; jQuery.culture = jQuery.cultures["fr-FR"];
</pre> </pre>
</p> </p>


Expand All @@ -78,7 +78,7 @@ jQuery.preferCulture(["es-MX", "fr-FR"]);
alert(jQuery.culture.name) // 'fr' alert(jQuery.culture.name) // 'fr'
</pre> </pre>


In any case, if no match is found, the 'en' culture is selected. In any case, if no match is found, the 'default' culture is selected.
</p> </p>


<a name="find"></a> <a name="find"></a>
Expand Down Expand Up @@ -149,7 +149,7 @@ jQuery.localize("myplugin", "fr", {
var obj = jQuery.localize("myplugin", "fr"); var obj = jQuery.localize("myplugin", "fr");
alert(obj.foo); // "foo" alert(obj.foo); // "foo"
</pre> </pre>
Note that localize() will find the closest match available per the same semantics as the jQuery.findClosestCulture function. If there is no match, the translation given is for the 'en' culture, if one was specified. Note that localize() will find the closest match available per the same semantics as the jQuery.findClosestCulture function. If there is no match, the translation given is for the 'default' culture, if one was specified.
<pre> <pre>
jQuery.localize("myplugin", "", { jQuery.localize("myplugin", "", {
foo: "foo (en)", foo: "foo (en)",
Expand Down Expand Up @@ -197,9 +197,9 @@ Using this mechanism, the 'fr' culture will be created if it does not exist. And
Each culture is defined in its own script with the naming scheme jQuery.glob.&lt;code&gt;.js (along with its minified version, jQuery.glob.&lt;code&gt;.min.js). You may include any number of these scripts, making them available in the jQuery.cultures mapping. Including one of these scripts does NOT automatically make it the default culture selected with jQuery.culture. Each culture is defined in its own script with the naming scheme jQuery.glob.&lt;code&gt;.js (along with its minified version, jQuery.glob.&lt;code&gt;.min.js). You may include any number of these scripts, making them available in the jQuery.cultures mapping. Including one of these scripts does NOT automatically make it the default culture selected with jQuery.culture.
</p> </p>
<p> <p>
The default culture that comes with jQuery.glob.js is 'en', and heavily commented, describing the purpose of each of the fields defined by a culture. Note that every culture includes all of these fields, even if they are the same as this culture. However, the script uses jQuery's $.extend to copy from this culture, so looking at the raw scripts will only show you what is different in that culture from 'en'. The 'en' culture is listed here along with the comments: The default culture that comes with jQuery.glob.js is 'default', and heavily commented, describing the purpose of each of the fields defined by a culture. Note that every culture includes all of these fields, even if they are the same as this culture. However, the script uses jQuery's $.extend to copy from this culture, so looking at the raw scripts will only show you what is different in that culture from 'default'. The 'default' culture is listed here along with the comments:
<pre> <pre>
jQuery.cultures.en = { jQuery.cultures['default'] = {
// A unique name for the culture in the form &lt;language code&gt;-&lt;country/region code&lt; // A unique name for the culture in the form &lt;language code&gt;-&lt;country/region code&lt;
name: "English", name: "English",
// the name of the culture in the english language // the name of the culture in the english language
Expand Down
19 changes: 10 additions & 9 deletions jquery.glob.js
Expand Up @@ -5,12 +5,13 @@
(function($) { (function($) {


var localized = { en: {} }; var localized = { en: {} };
localized["default"] = localized.en;


$.extend({ $.extend({
findClosestCulture: function(name) { findClosestCulture: function(name) {
var match; var match;
if ( !name ) { if ( !name ) {
match = $.culture || $.cultures.en; match = $.culture || $.cultures["default"];
} }
else if ( $.isPlainObject( name ) ) { else if ( $.isPlainObject( name ) ) {
match = name; match = name;
Expand Down Expand Up @@ -46,11 +47,11 @@ $.extend({
return match || null; return match || null;
}, },
preferCulture: function(name) { preferCulture: function(name) {
$.culture = $.findClosestCulture( name ) || $.cultures.en; $.culture = $.findClosestCulture( name ) || $.cultures["default"];
}, },
localize: function(key, culture, value) { localize: function(key, culture, value) {
if (typeof culture === 'string') { if (typeof culture === 'string') {
culture = culture || "en"; culture = culture || "default";
culture = $.cultures[ culture ] || { name: culture }; culture = $.cultures[ culture ] || { name: culture };
} }
var local = localized[ culture.name ]; var local = localized[ culture.name ];
Expand All @@ -70,7 +71,7 @@ $.extend({
value = language[ key ]; value = language[ key ];
} }
if ( typeof value === 'undefined' ) { if ( typeof value === 'undefined' ) {
value = localized.en[ key ]; value = localized["default"][ key ];
} }
} }
} }
Expand Down Expand Up @@ -193,8 +194,8 @@ $.extend({


// 1. When defining a culture, all fields are required except the ones stated as optional. // 1. When defining a culture, all fields are required except the ones stated as optional.
// 2. You can use $.extend to copy an existing culture and provide only the differing values, // 2. You can use $.extend to copy an existing culture and provide only the differing values,
// a good practice since most cultures do not differ too much from the 'en' culture. // a good practice since most cultures do not differ too much from the 'default' culture.
// DO use the 'en' culture if you do this, as it is the only one that definitely // DO use the 'default' culture if you do this, as it is the only one that definitely
// exists. // exists.
// 3. Other plugins may add to the culture information provided by extending it. However, // 3. Other plugins may add to the culture information provided by extending it. However,
// that plugin may extend it prior to the culture being defined, or after. Therefore, // that plugin may extend it prior to the culture being defined, or after. Therefore,
Expand All @@ -206,12 +207,12 @@ $.extend({
// it may be dynamically changed at any time to one of the calendars in ".calendars". // it may be dynamically changed at any time to one of the calendars in ".calendars".


// To define a culture, use the following pattern, which handles defining the culture based // To define a culture, use the following pattern, which handles defining the culture based
// on the 'en culture, extending it with the existing culture if it exists, and defining // on the 'default culture, extending it with the existing culture if it exists, and defining
// it if it does not exist. // it if it does not exist.
// $.cultures.foo = $.extend(true, $.extend(true, {}, $.cultures.en, fooCulture), $.cultures.foo) // $.cultures.foo = $.extend(true, $.extend(true, {}, $.cultures['default'], fooCulture), $.cultures.foo)


var cultures = $.cultures = $.cultures || {}; var cultures = $.cultures = $.cultures || {};
var en = cultures.en = $.extend(true, { var en = cultures["default"] = cultures.en = $.extend(true, {
// A unique name for the culture in the form <language code>-<country/region code> // A unique name for the culture in the form <language code>-<country/region code>
name: "en", name: "en",
// the name of the culture in the english language // the name of the culture in the english language
Expand Down

0 comments on commit 72df551

Please sign in to comment.