bistringbundle.html
来自「ajax 框价.是个好工具.javascript 矿家.可以用在任何平台.」· HTML 代码 · 共 490 行
HTML
490 行
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><!--Generated using api.website.xsl version 2003-07-17--><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"><title>BiStringBundle</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type="text/css" rel="stylesheet" href="api.css"><script type="text/javascript"> function showDerivedClasses() { var ul = document.getElementById("api-derived-classes"); var lis = ul.childNodes; var l = lis.length; for (var i = 1; i < l; i++) lis[i].style.display = ""; lis[0].style.display = "none"; } </script></head><body><h1 id="BiStringBundle">BiStringBundle</h1><p>This class is used to make creating multilingual applications easier. The string bundle is uses one hash table (objects in JavaScript) for every language and falls back on English (<code>"en"</code>) in case the user language is not available.</p><p>This class extends <code><a href="BiEventTarget.html">BiEventTarget</a></code> and therefore all methods and fields available for <code><a href="BiEventTarget.html">BiEventTarget</a></code> are also available for <code>BiStringBundle</code>.</p><ul class="partial-class-tree"><li><code><a href="BiObject.html">BiObject</a></code><ul><li><code><a href="BiEventTarget.html">BiEventTarget</a></code><ul><li><code>BiStringBundle</code><ul id="api-derived-classes"></ul></li></ul></li></ul></li></ul><h2>Constructor</h2><p><code> new BiStringBundle()</code></p><h3>Parameters</h3><p>No parameters.</p><h2>Properties</h2><table><thead><tr><td>Name</td><td>Type</td><td class="get-header">get</td><td class="set-header">set</td><td>Descripton</td></tr></thead><tbody><tr><td><a name="bundles"></a><code>bundles</code></td><td><code class="type">Object[]</code></td><td class="get-column"><img src="check.png" alt="checked"></td><td class="set-column"></td><td>Returns the added bundles as an array</td></tr><tr><td><a name="language"></a><code>language</code></td><td><code class="type">String</code></td><td class="get-column"><img src="check.png" alt="checked"></td><td class="set-column"><img src="check.png" alt="checked"></td><td>The current language</td></tr><tr><td><a name="languages"></a><code>languages</code></td><td><code class="type">String[]</code></td><td class="get-column"><img src="check.png" alt="checked"></td><td class="set-column"></td><td>Returns the languages supported by the string bundle</td></tr><tr><td><a name="majorLanguage"></a><code>majorLanguage</code></td><td><code class="type">String</code></td><td class="get-column"><img src="check.png" alt="checked"></td><td class="set-column"></td><td>The current major language. For example if the current language is <code>"en-us"</code> then this returns <code>"en"</code>.</td></tr><tr><td><a name="userLanguage"></a><code>userLanguage</code></td><td><code class="type">String</code></td><td class="get-column"><img src="check.png" alt="checked"></td><td class="set-column"></td><td>The language of the user's operating environment</td></tr></tbody></table><h2>Methods</h2><table><thead><tr><td>Name</td><td>Description</td></tr></thead><tbody><tr><td><code><a href="#addBundle">addBundle</a></code></td><td>Adds a bundle and associates that with a certain language code</td></tr><tr><td><code><a href="#appendBundle">appendBundle</a></code></td><td>This adds key value pairs to an existing bundle. This allows you to modify an existing bundle with more strings</td></tr><tr><td><code><a href="#getBundleForLanguage">getBundleForLanguage</a></code></td><td>Returns the bundle (hash table) for the given language code. This will return the best match. If you pass "zh-cn" it will try to find the bundles in the following order; "zh-cn", "zh", <code><a href="#language">language</a></code>, <code><a href="#majorLanguage">majorLanguage</a></code>, "en" and if all these fails an empty bundle (object) will be returned.</td></tr><tr><td><code><a href="#getFormattedString">getFormattedString</a></code></td><td>Returns the string for the given string id. The string is then formatted so that %1 to %n are replaced by the extra arguments to this method. This method does not allow you to specify the language. If that is needed use <code><a href="#getString">getString</a></code> followed by <code><a href="#formatString">formatString</a></code>.</td></tr><tr><td><code><a href="#getString">getString</a></code></td><td>Returns the string for the given string id. The second argument is the language code to get the string for. If left out then the current language for the string bundle is used.</td></tr><tr><td><code><a href="#getStringKeys">getStringKeys</a></code></td><td>Returns the keys used to identify the strings in the bundles</td></tr><tr><td><code><a href="#removeBundle">removeBundle</a></code></td><td>Removes the string bundle with the given language code</td></tr></tbody></table><h2>Events</h2><table><thead><tr><td>Name</td><td>Type</td><td class="bubbles-header">Bubbles</td><td>Descripton</td></tr></thead><tbody><tr><td><a name="change"></a><code>change</code></td><td><code class="type"> <code><a href="BiEvent.html">BiEvent</a></code> </code></td><td class="bubbles-column"></td><td>This event is fired when the current strings changes in some way. This happens when the language is changed or a new bundle is added with the current language.</td></tr></tbody></table><h2>Static Methods</h2><table><thead><tr><td>Name</td><td>Description</td></tr></thead><tbody><tr><td><code><a href="#formatString">formatString</a></code></td><td>Takes a string containing %1 to %n and 0 to n extra arguments that will replace the %n strings.</td></tr></tbody></table><h2>Static Fields</h2><p>None.</p><h2>Remarks</h2><p>The string bundles (that are added using <code><a href="#addBundle">addBundle</a></code> should be plain JavaScript objects (hash tables) with the following form:<br> <br> <code>var enBundle = {<br> languageCode: "en",<br> languageName: "English",<br> selectLanguage: "Select Language:",<br> checkingForIsLoggedIn: "Checking if already logged in...",<br> windowCaption: "Download the Bindows\u2122 Framework"<br> };</code> <br> <br> The languageCode and languageName fields are not special in any way. It is just a good practice to include them and they are often useful to the application.<br> <br> Typical usage looks something like this:<br> <br> <code>var stringBundle = new<code><a href="BiStringBundle.html">BiStringBundle</a></code>;<br> stringBundle.addBundle("en", enBundle);<br> ...<br> someLabel.setText( stringBundle.getString("someLabelText") );</code> </p><h2>Method Details</h2><h3><a name="addBundle"></a>addBundle</h3><p>Adds a bundle and associates that with a certain language code</p><h4>Syntax</h4><pre class="method-syntax">object.addBundle(<span class="methodArgument">sLanguage</span>, <span class="methodArgument">oStringMap</span>)</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sLanguage</code></td><td><code class="type">String</code></td><td class="optional-column"></td><td></td><td>The language code for the string bundle to add.</td></tr><tr><td><code>oStringMap</code></td><td><code class="type">Object</code></td><td class="optional-column"></td><td></td><td>The hash table used to map string identifiers to strings.</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">void</code></p><h3><a name="appendBundle"></a>appendBundle</h3><p>This adds key value pairs to an existing bundle. This allows you to modify an existing bundle with more strings</p><h4>Syntax</h4><pre class="method-syntax">object.appendBundle(<span class="methodArgument">sLanguage</span>, <span class="methodArgument">oStringMap</span>)</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sLanguage</code></td><td><code class="type">String</code></td><td class="optional-column"></td><td></td><td>The language code for the string bundle to append.</td></tr><tr><td><code>oStringMap</code></td><td><code class="type">Object</code></td><td class="optional-column"></td><td></td><td>The hash table used to map string identifiers to strings.</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">void</code></p><h3><a name="getBundleForLanguage"></a>getBundleForLanguage</h3><p>Returns the bundle (hash table) for the given language code. This will return the best match. If you pass "zh-cn" it will try to find the bundles in the following order; "zh-cn", "zh", <code><a href="#language">language</a></code>, <code><a href="#majorLanguage">majorLanguage</a></code>, "en" and if all these fails an empty bundle (object) will be returned.</p><h4>Syntax</h4><pre class="method-syntax">object.getBundleForLanguage([<span class="methodArgument">sLanguage</span>])</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sLanguage</code></td><td><code class="type">String</code></td><td class="optional-column"><img src="check.png" alt="checked"></td><td></td><td>The language code of the string bundle to return. If left out the default language is used.</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">Object</code></p><h3><a name="getFormattedString"></a>getFormattedString</h3><p>Returns the string for the given string id. The string is then formatted so that %1 to %n are replaced by the extra arguments to this method. This method does not allow you to specify the language. If that is needed use <code><a href="#getString">getString</a></code> followed by <code><a href="#formatString">formatString</a></code>.</p><h4>Syntax</h4><pre class="method-syntax">object.getFormattedString(<span class="methodArgument">sStringId</span> [, <span class="methodArgument">args</span>])</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sStringId</code></td><td><code class="type">String</code></td><td class="optional-column"></td><td></td><td>The id for the string to retreive</td></tr><tr><td><code>args</code></td><td><code class="type">String</code></td><td class="optional-column"><img src="check.png" alt="checked"></td><td></td><td>Optional arguments (as many as you wish) that will replace the '%n' in the pattern</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">String</code></p><h3><a name="getString"></a>getString</h3><p>Returns the string for the given string id. The second argument is the language code to get the string for. If left out then the current language for the string bundle is used.</p><h4>Syntax</h4><pre class="method-syntax">object.getString(<span class="methodArgument">sStringId</span> [, <span class="methodArgument">sLanguage</span>])</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sStringId</code></td><td><code class="type">String</code></td><td class="optional-column"></td><td></td><td>The id for the string to retreive</td></tr><tr><td><code>sLanguage</code></td><td><code class="type">String</code></td><td class="optional-column"><img src="check.png" alt="checked"></td><td></td><td>The language code of the string to return </td></tr></tbody></table><h4>Return Type</h4><p><code class="type">String</code></p><h3><a name="getStringKeys"></a>getStringKeys</h3><p>Returns the keys used to identify the strings in the bundles</p><h4>Syntax</h4><pre class="method-syntax">object.getStringKeys([<span class="methodArgument">sLanguage</span>])</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sLanguage</code></td><td><code class="type">String</code></td><td class="optional-column"><img src="check.png" alt="checked"></td><td></td><td>The language code to use when getting the strings in the bundle. If left out the current language is is used</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">String[]</code></p><h3><a name="removeBundle"></a>removeBundle</h3><p>Removes the string bundle with the given language code</p><h4>Syntax</h4><pre class="method-syntax">object.removeBundle(<span class="methodArgument">sLanguage</span>)</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sLanguage</code></td><td><code class="type">String</code></td><td class="optional-column"></td><td></td><td>The language code of the string bundle to remove</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">void</code></p><h2>Static Method Details</h2><h3><a name="formatString"></a>formatString</h3><p>Takes a string containing %1 to %n and 0 to n extra arguments that will replace the %n strings.</p><h4>Syntax</h4><pre class="method-syntax">BiStringBundle.formatString(<span class="methodArgument">sPattern</span> [, <span class="methodArgument">args</span>])</pre><h4>Parameters</h4><table><thead><tr><td>Name</td><td>Type</td><td class="optional-header">Optional</td><td>Default</td><td>Descripton</td></tr></thead><tbody><tr><td><code>sPattern</code></td><td><code class="type">String</code></td><td class="optional-column"></td><td></td><td>A string containing '%n' where '%n' will be replaced by the remaining arguments.</td></tr><tr><td><code>args</code></td><td><code class="type">String</code></td><td class="optional-column"><img src="check.png" alt="checked"></td><td></td><td>Optional arguments (as many as you wish) that will replace the '%n' in the pattern</td></tr></tbody></table><h4>Return Type</h4><p><code class="type">String</code></p></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?