This commit is contained in:
518
node_modules/node-polyglot/docs/docco.css
generated
vendored
Normal file
518
node_modules/node-polyglot/docs/docco.css
generated
vendored
Normal file
@@ -0,0 +1,518 @@
|
||||
/*--------------------- Typography ----------------------------*/
|
||||
|
||||
@font-face {
|
||||
font-family: 'aller-light';
|
||||
src: url('public/fonts/aller-light.eot');
|
||||
src: url('public/fonts/aller-light.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/aller-light.woff') format('woff'),
|
||||
url('public/fonts/aller-light.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'aller-bold';
|
||||
src: url('public/fonts/aller-bold.eot');
|
||||
src: url('public/fonts/aller-bold.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/aller-bold.woff') format('woff'),
|
||||
url('public/fonts/aller-bold.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'roboto-black';
|
||||
src: url('public/fonts/roboto-black.eot');
|
||||
src: url('public/fonts/roboto-black.eot?#iefix') format('embedded-opentype'),
|
||||
url('public/fonts/roboto-black.woff') format('woff'),
|
||||
url('public/fonts/roboto-black.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/*--------------------- Layout ----------------------------*/
|
||||
html { height: 100%; }
|
||||
body {
|
||||
font-family: "aller-light";
|
||||
font-size: 14px;
|
||||
line-height: 18px;
|
||||
color: #30404f;
|
||||
margin: 0; padding: 0;
|
||||
height:100%;
|
||||
}
|
||||
#container { min-height: 100%; }
|
||||
|
||||
a {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
b, strong {
|
||||
font-weight: normal;
|
||||
font-family: "aller-bold";
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 15px 0 0px;
|
||||
}
|
||||
.annotation ul, .annotation ol {
|
||||
margin: 25px 0;
|
||||
}
|
||||
.annotation ul li, .annotation ol li {
|
||||
font-size: 14px;
|
||||
line-height: 18px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: #112233;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
font-family: "roboto-black";
|
||||
text-transform: uppercase;
|
||||
margin: 30px 0 15px 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.26em;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
background: 1px #ddd;
|
||||
height: 1px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
pre, tt, code {
|
||||
font-size: 12px; line-height: 16px;
|
||||
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
.annotation pre {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 7px 10px;
|
||||
background: #fcfcfc;
|
||||
-moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
|
||||
-webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
|
||||
box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
|
||||
overflow-x: auto;
|
||||
}
|
||||
.annotation pre code {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
|
||||
blockquote {
|
||||
border-left: 5px solid #ccc;
|
||||
margin: 0;
|
||||
padding: 1px 0 1px 1em;
|
||||
}
|
||||
.sections blockquote p {
|
||||
font-family: Menlo, Consolas, Monaco, monospace;
|
||||
font-size: 12px; line-height: 16px;
|
||||
color: #999;
|
||||
margin: 10px 0 0;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
ul.sections {
|
||||
list-style: none;
|
||||
padding:0 0 5px 0;;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
/*
|
||||
Force border-box so that % widths fit the parent
|
||||
container without overlap because of margin/padding.
|
||||
|
||||
More Info : http://www.quirksmode.org/css/box.html
|
||||
*/
|
||||
ul.sections > li > div {
|
||||
-moz-box-sizing: border-box; /* firefox */
|
||||
-ms-box-sizing: border-box; /* ie */
|
||||
-webkit-box-sizing: border-box; /* webkit */
|
||||
-khtml-box-sizing: border-box; /* konqueror */
|
||||
box-sizing: border-box; /* css3 */
|
||||
}
|
||||
|
||||
|
||||
/*---------------------- Jump Page -----------------------------*/
|
||||
#jump_to, #jump_page {
|
||||
margin: 0;
|
||||
background: white;
|
||||
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
||||
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
|
||||
font: 16px Arial;
|
||||
cursor: pointer;
|
||||
text-align: right;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#jump_to a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#jump_to a.large {
|
||||
display: none;
|
||||
}
|
||||
#jump_to a.small {
|
||||
font-size: 22px;
|
||||
font-weight: bold;
|
||||
color: #676767;
|
||||
}
|
||||
|
||||
#jump_to, #jump_wrapper {
|
||||
position: fixed;
|
||||
right: 0; top: 0;
|
||||
padding: 10px 15px;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
#jump_wrapper {
|
||||
display: none;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
#jump_to:hover #jump_wrapper {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#jump_page_wrapper{
|
||||
position: fixed;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
#jump_page {
|
||||
padding: 5px 0 3px;
|
||||
margin: 0 0 25px 25px;
|
||||
max-height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#jump_page .source {
|
||||
display: block;
|
||||
padding: 15px;
|
||||
text-decoration: none;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
#jump_page .source:hover {
|
||||
background: #f5f5ff;
|
||||
}
|
||||
|
||||
#jump_page .source:first-child {
|
||||
}
|
||||
|
||||
/*---------------------- Low resolutions (> 320px) ---------------------*/
|
||||
@media only screen and (min-width: 320px) {
|
||||
.pilwrap { display: none; }
|
||||
|
||||
ul.sections > li > div {
|
||||
display: block;
|
||||
padding:5px 10px 0 10px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.content {
|
||||
overflow-x:auto;
|
||||
-webkit-box-shadow: inset 0 0 5px #e5e5ee;
|
||||
box-shadow: inset 0 0 5px #e5e5ee;
|
||||
border: 1px solid #dedede;
|
||||
margin:5px 10px 5px 10px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation pre {
|
||||
margin: 7px 0 7px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation p tt, .annotation code {
|
||||
background: #f8f8ff;
|
||||
border: 1px solid #dedede;
|
||||
font-size: 12px;
|
||||
padding: 0 0.2em;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- (> 481px) ---------------------*/
|
||||
@media only screen and (min-width: 481px) {
|
||||
#container {
|
||||
position: relative;
|
||||
}
|
||||
body {
|
||||
background-color: #F5F5FF;
|
||||
font-size: 15px;
|
||||
line-height: 21px;
|
||||
}
|
||||
pre, tt, code {
|
||||
line-height: 18px;
|
||||
}
|
||||
p, ul, ol {
|
||||
margin: 0 0 15px;
|
||||
}
|
||||
|
||||
|
||||
#jump_to {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
#jump_wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
#jump_to, #jump_page {
|
||||
font: 10px Arial;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
#jump_page .source {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
#jump_to a.large {
|
||||
display: inline-block;
|
||||
}
|
||||
#jump_to a.small {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#background {
|
||||
position: absolute;
|
||||
top: 0; bottom: 0;
|
||||
width: 350px;
|
||||
background: #fff;
|
||||
border-right: 1px solid #e5e5ee;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol {
|
||||
padding-left: 40px;
|
||||
}
|
||||
|
||||
ul.sections > li {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
ul.sections > li > div {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation {
|
||||
max-width: 350px;
|
||||
min-width: 350px;
|
||||
min-height: 5px;
|
||||
padding: 13px;
|
||||
overflow-x: hidden;
|
||||
white-space: normal;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
}
|
||||
ul.sections > li > div.annotation pre {
|
||||
margin: 15px 0 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.content {
|
||||
padding: 13px;
|
||||
vertical-align: top;
|
||||
border: none;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.pilwrap {
|
||||
position: relative;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.pilcrow {
|
||||
font: 12px Arial;
|
||||
text-decoration: none;
|
||||
color: #454545;
|
||||
position: absolute;
|
||||
top: 3px; left: -20px;
|
||||
padding: 1px 2px;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s linear;
|
||||
}
|
||||
.for-h1 .pilcrow {
|
||||
top: 47px;
|
||||
}
|
||||
.for-h2 .pilcrow, .for-h3 .pilcrow, .for-h4 .pilcrow {
|
||||
top: 35px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation:hover .pilcrow {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- (> 1025px) ---------------------*/
|
||||
@media only screen and (min-width: 1025px) {
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
#background {
|
||||
width: 525px;
|
||||
}
|
||||
ul.sections > li > div.annotation {
|
||||
max-width: 525px;
|
||||
min-width: 525px;
|
||||
padding: 10px 25px 1px 50px;
|
||||
}
|
||||
ul.sections > li > div.content {
|
||||
padding: 9px 15px 16px 25px;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------- Syntax Highlighting -----------------------------*/
|
||||
|
||||
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
||||
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
|
||||
/*
|
||||
|
||||
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
||||
|
||||
*/
|
||||
|
||||
pre code {
|
||||
display: block; padding: 0.5em;
|
||||
color: #000;
|
||||
background: #f8f8ff
|
||||
}
|
||||
|
||||
pre .hljs-comment,
|
||||
pre .hljs-template_comment,
|
||||
pre .hljs-diff .hljs-header,
|
||||
pre .hljs-javadoc {
|
||||
color: #408080;
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
pre .hljs-keyword,
|
||||
pre .hljs-assignment,
|
||||
pre .hljs-literal,
|
||||
pre .hljs-css .hljs-rule .hljs-keyword,
|
||||
pre .hljs-winutils,
|
||||
pre .hljs-javascript .hljs-title,
|
||||
pre .hljs-lisp .hljs-title,
|
||||
pre .hljs-subst {
|
||||
color: #954121;
|
||||
/*font-weight: bold*/
|
||||
}
|
||||
|
||||
pre .hljs-number,
|
||||
pre .hljs-hexcolor {
|
||||
color: #40a070
|
||||
}
|
||||
|
||||
pre .hljs-string,
|
||||
pre .hljs-tag .hljs-value,
|
||||
pre .hljs-phpdoc,
|
||||
pre .hljs-tex .hljs-formula {
|
||||
color: #219161;
|
||||
}
|
||||
|
||||
pre .hljs-title,
|
||||
pre .hljs-id {
|
||||
color: #19469D;
|
||||
}
|
||||
pre .hljs-params {
|
||||
color: #00F;
|
||||
}
|
||||
|
||||
pre .hljs-javascript .hljs-title,
|
||||
pre .hljs-lisp .hljs-title,
|
||||
pre .hljs-subst {
|
||||
font-weight: normal
|
||||
}
|
||||
|
||||
pre .hljs-class .hljs-title,
|
||||
pre .hljs-haskell .hljs-label,
|
||||
pre .hljs-tex .hljs-command {
|
||||
color: #458;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
pre .hljs-tag,
|
||||
pre .hljs-tag .hljs-title,
|
||||
pre .hljs-rules .hljs-property,
|
||||
pre .hljs-django .hljs-tag .hljs-keyword {
|
||||
color: #000080;
|
||||
font-weight: normal
|
||||
}
|
||||
|
||||
pre .hljs-attribute,
|
||||
pre .hljs-variable,
|
||||
pre .hljs-instancevar,
|
||||
pre .hljs-lisp .hljs-body {
|
||||
color: #008080
|
||||
}
|
||||
|
||||
pre .hljs-regexp {
|
||||
color: #B68
|
||||
}
|
||||
|
||||
pre .hljs-class {
|
||||
color: #458;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
pre .hljs-symbol,
|
||||
pre .hljs-ruby .hljs-symbol .hljs-string,
|
||||
pre .hljs-ruby .hljs-symbol .hljs-keyword,
|
||||
pre .hljs-ruby .hljs-symbol .hljs-keymethods,
|
||||
pre .hljs-lisp .hljs-keyword,
|
||||
pre .hljs-tex .hljs-special,
|
||||
pre .hljs-input_number {
|
||||
color: #990073
|
||||
}
|
||||
|
||||
pre .hljs-builtin,
|
||||
pre .hljs-constructor,
|
||||
pre .hljs-built_in,
|
||||
pre .hljs-lisp .hljs-title {
|
||||
color: #0086b3
|
||||
}
|
||||
|
||||
pre .hljs-preprocessor,
|
||||
pre .hljs-pi,
|
||||
pre .hljs-doctype,
|
||||
pre .hljs-shebang,
|
||||
pre .hljs-cdata {
|
||||
color: #999;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
pre .hljs-deletion {
|
||||
background: #fdd
|
||||
}
|
||||
|
||||
pre .hljs-addition {
|
||||
background: #dfd
|
||||
}
|
||||
|
||||
pre .hljs-diff .hljs-change {
|
||||
background: #0086b3
|
||||
}
|
||||
|
||||
pre .hljs-chunk {
|
||||
color: #aaa
|
||||
}
|
||||
|
||||
pre .hljs-tex .hljs-formula {
|
||||
opacity: 0.5;
|
||||
}
|
||||
613
node_modules/node-polyglot/docs/polyglot.html
generated
vendored
Normal file
613
node_modules/node-polyglot/docs/polyglot.html
generated
vendored
Normal file
@@ -0,0 +1,613 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>polyglot.js</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
||||
<link rel="stylesheet" media="all" href="docco.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="background"></div>
|
||||
|
||||
<ul class="sections">
|
||||
|
||||
<li id="title">
|
||||
<div class="annotation">
|
||||
<h1>polyglot.js</h1>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<pre><code>(c) <span class="hljs-number">2012</span><span class="hljs-number">-2018</span> Airbnb, Inc.
|
||||
|
||||
polyglot.js may be freely distributed under the terms <span class="hljs-keyword">of</span> the BSD
|
||||
license. For all licensing information, details, and documention:
|
||||
http:<span class="hljs-comment">//airbnb.github.com/polyglot.js</span>
|
||||
</code></pre><p>Polyglot.js is an I18n helper library written in JavaScript, made to
|
||||
work both in the browser and in Node. It provides a simple solution for
|
||||
interpolation and pluralization, based off of Airbnb’s
|
||||
experience adding I18n functionality to its Backbone.js and Node apps.</p>
|
||||
<p>Polylglot is agnostic to your translation backend. It doesn’t perform any
|
||||
translation; it simply gives you a way to manage translated phrases from
|
||||
your client- or server-side JavaScript application.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-meta">
|
||||
'use strict'</span>;
|
||||
|
||||
<span class="hljs-keyword">var</span> forEach = <span class="hljs-built_in">require</span>(<span class="hljs-string">'for-each'</span>);
|
||||
<span class="hljs-keyword">var</span> warning = <span class="hljs-built_in">require</span>(<span class="hljs-string">'warning'</span>);
|
||||
<span class="hljs-keyword">var</span> has = <span class="hljs-built_in">require</span>(<span class="hljs-string">'has'</span>);
|
||||
<span class="hljs-keyword">var</span> trim = <span class="hljs-built_in">require</span>(<span class="hljs-string">'string.prototype.trim'</span>);
|
||||
|
||||
<span class="hljs-keyword">var</span> warn = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">warn</span>(<span class="hljs-params">message</span>) </span>{
|
||||
warning(<span class="hljs-literal">false</span>, message);
|
||||
};
|
||||
|
||||
<span class="hljs-keyword">var</span> replace = <span class="hljs-built_in">String</span>.prototype.replace;
|
||||
<span class="hljs-keyword">var</span> split = <span class="hljs-built_in">String</span>.prototype.split;</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
</div>
|
||||
<h4 id="pluralization-methods">Pluralization methods</h4>
|
||||
<p>The string that separates the different phrase possibilities.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">var</span> delimiter = <span class="hljs-string">'||||'</span>;
|
||||
|
||||
<span class="hljs-keyword">var</span> russianPluralGroups = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
|
||||
<span class="hljs-keyword">var</span> end = n % <span class="hljs-number">10</span>;
|
||||
<span class="hljs-keyword">if</span> (n !== <span class="hljs-number">11</span> && end === <span class="hljs-number">1</span>) {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
|
||||
}
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-number">2</span> <= end && end <= <span class="hljs-number">4</span> && !(n >= <span class="hljs-number">12</span> && n <= <span class="hljs-number">14</span>)) {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
|
||||
}
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">2</span>;
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
</div>
|
||||
<p>Mapping from pluralization group plural logic.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">var</span> pluralTypes = {
|
||||
<span class="hljs-attr">arabic</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
</div>
|
||||
<p><a href="http://www.arabeyes.org/Plural_Forms">http://www.arabeyes.org/Plural_Forms</a></p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (n < <span class="hljs-number">3</span>) { <span class="hljs-keyword">return</span> n; }
|
||||
<span class="hljs-keyword">var</span> lastTwo = n % <span class="hljs-number">100</span>;
|
||||
<span class="hljs-keyword">if</span> (lastTwo >= <span class="hljs-number">3</span> && lastTwo <= <span class="hljs-number">10</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">3</span>;
|
||||
<span class="hljs-keyword">return</span> lastTwo >= <span class="hljs-number">11</span> ? <span class="hljs-number">4</span> : <span class="hljs-number">5</span>;
|
||||
},
|
||||
<span class="hljs-attr">bosnian_serbian</span>: russianPluralGroups,
|
||||
<span class="hljs-attr">chinese</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; },
|
||||
<span class="hljs-attr">croatian</span>: russianPluralGroups,
|
||||
<span class="hljs-attr">french</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{ <span class="hljs-keyword">return</span> n > <span class="hljs-number">1</span> ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>; },
|
||||
<span class="hljs-attr">german</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{ <span class="hljs-keyword">return</span> n !== <span class="hljs-number">1</span> ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>; },
|
||||
<span class="hljs-attr">russian</span>: russianPluralGroups,
|
||||
<span class="hljs-attr">lithuanian</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (n % <span class="hljs-number">10</span> === <span class="hljs-number">1</span> && n % <span class="hljs-number">100</span> !== <span class="hljs-number">11</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; }
|
||||
<span class="hljs-keyword">return</span> n % <span class="hljs-number">10</span> >= <span class="hljs-number">2</span> && n % <span class="hljs-number">10</span> <= <span class="hljs-number">9</span> && (n % <span class="hljs-number">100</span> < <span class="hljs-number">11</span> || n % <span class="hljs-number">100</span> > <span class="hljs-number">19</span>) ? <span class="hljs-number">1</span> : <span class="hljs-number">2</span>;
|
||||
},
|
||||
<span class="hljs-attr">czech</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (n === <span class="hljs-number">1</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; }
|
||||
<span class="hljs-keyword">return</span> (n >= <span class="hljs-number">2</span> && n <= <span class="hljs-number">4</span>) ? <span class="hljs-number">1</span> : <span class="hljs-number">2</span>;
|
||||
},
|
||||
<span class="hljs-attr">polish</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (n === <span class="hljs-number">1</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; }
|
||||
<span class="hljs-keyword">var</span> end = n % <span class="hljs-number">10</span>;
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">2</span> <= end && end <= <span class="hljs-number">4</span> && (n % <span class="hljs-number">100</span> < <span class="hljs-number">10</span> || n % <span class="hljs-number">100</span> >= <span class="hljs-number">20</span>) ? <span class="hljs-number">1</span> : <span class="hljs-number">2</span>;
|
||||
},
|
||||
<span class="hljs-attr">icelandic</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{ <span class="hljs-keyword">return</span> (n % <span class="hljs-number">10</span> !== <span class="hljs-number">1</span> || n % <span class="hljs-number">100</span> === <span class="hljs-number">11</span>) ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>; },
|
||||
<span class="hljs-attr">slovenian</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
|
||||
<span class="hljs-keyword">var</span> lastTwo = n % <span class="hljs-number">100</span>;
|
||||
<span class="hljs-keyword">if</span> (lastTwo === <span class="hljs-number">1</span>) {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
|
||||
}
|
||||
<span class="hljs-keyword">if</span> (lastTwo === <span class="hljs-number">2</span>) {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
|
||||
}
|
||||
<span class="hljs-keyword">if</span> (lastTwo === <span class="hljs-number">3</span> || lastTwo === <span class="hljs-number">4</span>) {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">2</span>;
|
||||
}
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">3</span>;
|
||||
}
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
</div>
|
||||
<p>Mapping from pluralization group to individual language codes/locales.
|
||||
Will look up based on exact match, if not found and it’s a locale will parse the locale
|
||||
for language code, and if that does not exist will default to ‘en’</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>var pluralTypeToLanguages = {
|
||||
arabic: ['ar'],
|
||||
bosnian_serbian: ['bs-Latn-BA', 'bs-Cyrl-BA', 'srl-RS', 'sr-RS'],
|
||||
chinese: ['id', 'id-ID', 'ja', 'ko', 'ko-KR', 'lo', 'ms', 'th', 'th-TH', 'zh'],
|
||||
croatian: ['hr', 'hr-HR'],
|
||||
german: ['fa', 'da', 'de', 'en', 'es', 'fi', 'el', 'he', 'hi-IN', 'hu', 'hu-HU', 'it', 'nl', 'no', 'pt', 'sv', 'tr'],
|
||||
french: ['fr', 'tl', 'pt-br'],
|
||||
russian: ['ru', 'ru-RU'],
|
||||
lithuanian: ['lt'],
|
||||
czech: ['cs', 'cs-CZ', 'sk'],
|
||||
polish: ['pl'],
|
||||
icelandic: ['is'],
|
||||
slovenian: ['sl-SL']
|
||||
};
|
||||
|
||||
function langToTypeMap(mapping) {
|
||||
var ret = {};
|
||||
forEach(mapping, function (langs, type) {
|
||||
forEach(langs, function (lang) {
|
||||
ret[lang] = type;
|
||||
});
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
function pluralTypeName(locale) {
|
||||
var langToPluralType = langToTypeMap(pluralTypeToLanguages);
|
||||
return langToPluralType[locale]
|
||||
|| langToPluralType[split.call(locale, /-/, 1)[0]]
|
||||
|| langToPluralType.en;
|
||||
}
|
||||
|
||||
function pluralTypeIndex(locale, count) {
|
||||
return pluralTypes[pluralTypeName(locale)](count);
|
||||
}
|
||||
|
||||
function escape(token) {
|
||||
return token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
function constructTokenRegex(opts) {
|
||||
var prefix = (opts && opts.prefix) || '%{';
|
||||
var suffix = (opts && opts.suffix) || '}';
|
||||
|
||||
if (prefix === delimiter || suffix === delimiter) {
|
||||
throw new RangeError('"' + delimiter + '" token is reserved for pluralization');
|
||||
}
|
||||
|
||||
return new RegExp(escape(prefix) + '(.*?)' + escape(suffix), 'g');
|
||||
}
|
||||
|
||||
var dollarRegex = /\$/g;
|
||||
var dollarBillsYall = '$$';
|
||||
var defaultTokenRegex = /%\{(.*?)\}/g;</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
</div>
|
||||
<h3 id="transformphrase-phrase-substitutions-locale-">transformPhrase(phrase, substitutions, locale)</h3>
|
||||
<p>Takes a phrase string and transforms it by choosing the correct
|
||||
plural form and interpolating it.</p>
|
||||
<pre><code>transformPhrase(<span class="hljs-string">'Hello, %{name}!'</span>, {<span class="hljs-attr">name</span>: <span class="hljs-string">'Spike'</span>});
|
||||
<span class="hljs-comment">// "Hello, Spike!"</span>
|
||||
</code></pre><p>The correct plural form is selected if substitutions.smart_count
|
||||
is set. You can pass in a number instead of an Object as <code>substitutions</code>
|
||||
as a shortcut for <code>smart_count</code>.</p>
|
||||
<pre><code>transformPhrase(<span class="hljs-string">'%{smart_count} new messages |||| 1 new message'</span>, {<span class="hljs-attr">smart_count</span>: <span class="hljs-number">1</span>}, <span class="hljs-string">'en'</span>);
|
||||
<span class="hljs-comment">// "1 new message"</span>
|
||||
|
||||
transformPhrase(<span class="hljs-string">'%{smart_count} new messages |||| 1 new message'</span>, {<span class="hljs-attr">smart_count</span>: <span class="hljs-number">2</span>}, <span class="hljs-string">'en'</span>);
|
||||
<span class="hljs-comment">// "2 new messages"</span>
|
||||
|
||||
transformPhrase(<span class="hljs-string">'%{smart_count} new messages |||| 1 new message'</span>, <span class="hljs-number">5</span>, <span class="hljs-string">'en'</span>);
|
||||
<span class="hljs-comment">// "5 new messages"</span>
|
||||
</code></pre><p>You should pass in a third argument, the locale, to specify the correct plural type.
|
||||
It defaults to <code>'en'</code> with 2 plural forms.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transformPhrase</span>(<span class="hljs-params">phrase, substitutions, locale, tokenRegex</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> phrase !== <span class="hljs-string">'string'</span>) {
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>(<span class="hljs-string">'Polyglot.transformPhrase expects argument #1 to be string'</span>);
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">if</span> (substitutions == <span class="hljs-literal">null</span>) {
|
||||
<span class="hljs-keyword">return</span> phrase;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">var</span> result = phrase;
|
||||
<span class="hljs-keyword">var</span> interpolationRegex = tokenRegex || defaultTokenRegex;</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
</div>
|
||||
<p>allow number as a pluralization shortcut</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> options = <span class="hljs-keyword">typeof</span> substitutions === <span class="hljs-string">'number'</span> ? { <span class="hljs-attr">smart_count</span>: substitutions } : substitutions;</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Select plural form: based on a phrase text that contains <code>n</code>
|
||||
plural forms separated by <code>delimiter</code>, a <code>locale</code>, and a <code>substitutions.smart_count</code>,
|
||||
choose the correct plural form. This is only done if <code>count</code> is set.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (options.smart_count != <span class="hljs-literal">null</span> && result) {
|
||||
<span class="hljs-keyword">var</span> texts = split.call(result, delimiter);
|
||||
result = trim(texts[pluralTypeIndex(locale || <span class="hljs-string">'en'</span>, options.smart_count)] || texts[<span class="hljs-number">0</span>]);
|
||||
}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
</div>
|
||||
<p>Interpolate: Creates a <code>RegExp</code> object for each interpolation placeholder.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> result = replace.call(result, interpolationRegex, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">expression, argument</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (!has(options, argument) || options[argument] == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span> expression; }</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
</div>
|
||||
<p>Ensure replacement value is escaped to prevent special $-prefixed regex replace tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> replace.call(options[argument], dollarRegex, dollarBillsYall);
|
||||
});
|
||||
|
||||
<span class="hljs-keyword">return</span> result;
|
||||
}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-class-constructor">Polyglot class constructor</h3>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Polyglot</span>(<span class="hljs-params">options</span>) </span>{
|
||||
<span class="hljs-keyword">var</span> opts = options || {};
|
||||
<span class="hljs-keyword">this</span>.phrases = {};
|
||||
<span class="hljs-keyword">this</span>.extend(opts.phrases || {});
|
||||
<span class="hljs-keyword">this</span>.currentLocale = opts.locale || <span class="hljs-string">'en'</span>;
|
||||
<span class="hljs-keyword">var</span> allowMissing = opts.allowMissing ? transformPhrase : <span class="hljs-literal">null</span>;
|
||||
<span class="hljs-keyword">this</span>.onMissingKey = <span class="hljs-keyword">typeof</span> opts.onMissingKey === <span class="hljs-string">'function'</span> ? opts.onMissingKey : allowMissing;
|
||||
<span class="hljs-keyword">this</span>.warn = opts.warn || warn;
|
||||
<span class="hljs-keyword">this</span>.tokenRegex = constructTokenRegex(opts.interpolation);
|
||||
}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-locale-locale-">polyglot.locale([locale])</h3>
|
||||
<p>Get or set locale. Internally, Polyglot only uses locale for pluralization.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.locale = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">newLocale</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (newLocale) <span class="hljs-keyword">this</span>.currentLocale = newLocale;
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.currentLocale;
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-extend-phrases-">polyglot.extend(phrases)</h3>
|
||||
<p>Use <code>extend</code> to tell Polyglot how to translate a given key.</p>
|
||||
<pre><code>polyglot.extend({
|
||||
<span class="hljs-string">"hello"</span>: <span class="hljs-string">"Hello"</span>,
|
||||
<span class="hljs-string">"hello_name"</span>: <span class="hljs-string">"Hello, %{name}"</span>
|
||||
});
|
||||
</code></pre><p>The key can be any string. Feel free to call <code>extend</code> multiple times;
|
||||
it will override any phrases with the same key, but leave existing phrases
|
||||
untouched.</p>
|
||||
<p>It is also possible to pass nested phrase objects, which get flattened
|
||||
into an object with the nested keys concatenated using dot notation.</p>
|
||||
<pre><code>polyglot.extend({
|
||||
<span class="hljs-string">"nav"</span>: {
|
||||
<span class="hljs-string">"hello"</span>: <span class="hljs-string">"Hello"</span>,
|
||||
<span class="hljs-string">"hello_name"</span>: <span class="hljs-string">"Hello, %{name}"</span>,
|
||||
<span class="hljs-string">"sidebar"</span>: {
|
||||
<span class="hljs-string">"welcome"</span>: <span class="hljs-string">"Welcome"</span>
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
<span class="hljs-built_in">console</span>.log(polyglot.phrases);
|
||||
<span class="hljs-comment">// {</span>
|
||||
<span class="hljs-comment">// 'nav.hello': 'Hello',</span>
|
||||
<span class="hljs-comment">// 'nav.hello_name': 'Hello, %{name}',</span>
|
||||
<span class="hljs-comment">// 'nav.sidebar.welcome': 'Welcome'</span>
|
||||
<span class="hljs-comment">// }</span>
|
||||
</code></pre><p><code>extend</code> accepts an optional second argument, <code>prefix</code>, which can be used
|
||||
to prefix every key in the phrases object with some string, using dot
|
||||
notation.</p>
|
||||
<pre><code>polyglot.extend({
|
||||
<span class="hljs-string">"hello"</span>: <span class="hljs-string">"Hello"</span>,
|
||||
<span class="hljs-string">"hello_name"</span>: <span class="hljs-string">"Hello, %{name}"</span>
|
||||
}, <span class="hljs-string">"nav"</span>);
|
||||
|
||||
<span class="hljs-built_in">console</span>.log(polyglot.phrases);
|
||||
<span class="hljs-comment">// {</span>
|
||||
<span class="hljs-comment">// 'nav.hello': 'Hello',</span>
|
||||
<span class="hljs-comment">// 'nav.hello_name': 'Hello, %{name}'</span>
|
||||
<span class="hljs-comment">// }</span>
|
||||
</code></pre><p>This feature is used internally to support nested phrase objects.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.extend = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">morePhrases, prefix</span>) </span>{
|
||||
forEach(morePhrases, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phrase, key</span>) </span>{
|
||||
<span class="hljs-keyword">var</span> prefixedKey = prefix ? prefix + <span class="hljs-string">'.'</span> + key : key;
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> phrase === <span class="hljs-string">'object'</span>) {
|
||||
<span class="hljs-keyword">this</span>.extend(phrase, prefixedKey);
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">this</span>.phrases[prefixedKey] = phrase;
|
||||
}
|
||||
}, <span class="hljs-keyword">this</span>);
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-unset-phrases-">polyglot.unset(phrases)</h3>
|
||||
<p>Use <code>unset</code> to selectively remove keys from a polyglot instance.</p>
|
||||
<pre><code>polyglot.unset(<span class="hljs-string">"some_key"</span>);
|
||||
polyglot.unset({
|
||||
<span class="hljs-string">"hello"</span>: <span class="hljs-string">"Hello"</span>,
|
||||
<span class="hljs-string">"hello_name"</span>: <span class="hljs-string">"Hello, %{name}"</span>
|
||||
});
|
||||
</code></pre><p>The unset method can take either a string (for the key), or an object hash with
|
||||
the keys that you would like to unset.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.unset = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">morePhrases, prefix</span>) </span>{
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> morePhrases === <span class="hljs-string">'string'</span>) {
|
||||
<span class="hljs-keyword">delete</span> <span class="hljs-keyword">this</span>.phrases[morePhrases];
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
forEach(morePhrases, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phrase, key</span>) </span>{
|
||||
<span class="hljs-keyword">var</span> prefixedKey = prefix ? prefix + <span class="hljs-string">'.'</span> + key : key;
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> phrase === <span class="hljs-string">'object'</span>) {
|
||||
<span class="hljs-keyword">this</span>.unset(phrase, prefixedKey);
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">delete</span> <span class="hljs-keyword">this</span>.phrases[prefixedKey];
|
||||
}
|
||||
}, <span class="hljs-keyword">this</span>);
|
||||
}
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-clear-">polyglot.clear()</h3>
|
||||
<p>Clears all phrases. Useful for special cases, such as freeing
|
||||
up memory if you have lots of phrases but no longer need to
|
||||
perform any translation. Also used internally by <code>replace</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.clear = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
|
||||
<span class="hljs-keyword">this</span>.phrases = {};
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-replace-phrases-">polyglot.replace(phrases)</h3>
|
||||
<p>Completely replace the existing phrases with a new set of phrases.
|
||||
Normally, just use <code>extend</code> to add more phrases, but under certain
|
||||
circumstances, you may want to make sure no old phrases are lying around.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.replace = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">newPhrases</span>) </span>{
|
||||
<span class="hljs-keyword">this</span>.clear();
|
||||
<span class="hljs-keyword">this</span>.extend(newPhrases);
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-t-key-options-">polyglot.t(key, options)</h3>
|
||||
<p>The most-used method. Provide a key, and <code>t</code> will return the
|
||||
phrase.</p>
|
||||
<pre><code>polyglot.t(<span class="hljs-string">"hello"</span>);
|
||||
=> <span class="hljs-string">"Hello"</span>
|
||||
</code></pre><p>The phrase value is provided first by a call to <code>polyglot.extend()</code> or
|
||||
<code>polyglot.replace()</code>.</p>
|
||||
<p>Pass in an object as the second argument to perform interpolation.</p>
|
||||
<pre><code>polyglot.t(<span class="hljs-string">"hello_name"</span>, {<span class="hljs-attr">name</span>: <span class="hljs-string">"Spike"</span>});
|
||||
=> <span class="hljs-string">"Hello, Spike"</span>
|
||||
</code></pre><p>If you like, you can provide a default value in case the phrase is missing.
|
||||
Use the special option key “_” to specify a default.</p>
|
||||
<pre><code>polyglot.t(<span class="hljs-string">"i_like_to_write_in_language"</span>, {
|
||||
<span class="hljs-attr">_</span>: <span class="hljs-string">"I like to write in %{language}."</span>,
|
||||
<span class="hljs-attr">language</span>: <span class="hljs-string">"JavaScript"</span>
|
||||
});
|
||||
=> <span class="hljs-string">"I like to write in JavaScript."</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.t = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">key, options</span>) </span>{
|
||||
<span class="hljs-keyword">var</span> phrase, result;
|
||||
<span class="hljs-keyword">var</span> opts = options == <span class="hljs-literal">null</span> ? {} : options;
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-keyword">this</span>.phrases[key] === <span class="hljs-string">'string'</span>) {
|
||||
phrase = <span class="hljs-keyword">this</span>.phrases[key];
|
||||
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> opts._ === <span class="hljs-string">'string'</span>) {
|
||||
phrase = opts._;
|
||||
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.onMissingKey) {
|
||||
<span class="hljs-keyword">var</span> onMissingKey = <span class="hljs-keyword">this</span>.onMissingKey;
|
||||
result = onMissingKey(key, opts, <span class="hljs-keyword">this</span>.currentLocale, <span class="hljs-keyword">this</span>.tokenRegex);
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">this</span>.warn(<span class="hljs-string">'Missing translation for key: "'</span> + key + <span class="hljs-string">'"'</span>);
|
||||
result = key;
|
||||
}
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> phrase === <span class="hljs-string">'string'</span>) {
|
||||
result = transformPhrase(phrase, opts, <span class="hljs-keyword">this</span>.currentLocale, <span class="hljs-keyword">this</span>.tokenRegex);
|
||||
}
|
||||
<span class="hljs-keyword">return</span> result;
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
</div>
|
||||
<h3 id="polyglot-has-key-">polyglot.has(key)</h3>
|
||||
<p>Check if polyglot has a translation for given key</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.prototype.has = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">key</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> has(<span class="hljs-keyword">this</span>.phrases, key);
|
||||
};</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
</div>
|
||||
<p>export transformPhrase</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Polyglot.transformPhrase = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transform</span>(<span class="hljs-params">phrase, substitutions, locale</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> transformPhrase(phrase, substitutions, locale);
|
||||
};
|
||||
|
||||
<span class="hljs-built_in">module</span>.exports = Polyglot;</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user