diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/intl | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/intl')
46 files changed, 5382 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/intl/collator/collator/index.html b/files/ja/web/javascript/reference/global_objects/intl/collator/collator/index.html new file mode 100644 index 0000000000..0a3e9b9b42 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/collator/collator/index.html @@ -0,0 +1,112 @@ +--- +title: Intl.Collator() コンストラクター +slug: Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator +tags: + - Collator + - Constructor + - Intl + - JavaScript + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator</code></strong> オブジェクトは、言語を考慮した文字列の比較を可能にするオブジェクトである collator のコンストラクターです。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-collator.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate">new Intl.Collator([<var>locales</var>[, <var>options</var>]])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code></dt> + <dd> + <p>任意。 BCP47 言語タグの文字列またはその配列。 <code>locales</code> 引数の一般的な形式や解釈については {{jsxref("Global_Objects/Intl", "Intl のページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。次のUnicode拡張キーが使用可能です。</p> + + <dl> + <dt><code>co</code></dt> + <dd>特定のロケールにおけるバリアントの比較方法を指定します。指定可能な値には "<code>big5han</code>", "<code>dict</code>", "<code>direct</code>", "<code>ducet</code>", "<code>gb2312</code>", "<code>phonebk</code>", "<code>phonetic</code>", "<code>pinyin</code>", "<code>reformed</code>", "<code>searchjl</code>", "<code>stroke</code>", "<code>trad</code>", "<code>unihan</code>" があります。なお "<code>standard</code>" と"<code>search</code>" については、 <code>options</code> 引数の <code>usage</code> プロパティによって代替されるため無視されます (下記参照)。</dd> + <dt><code>kn</code></dt> + <dd>"1" < "2" < "10" のように数値として比較を行うかどうかです。可能な値は "<code>true</code>" および "<code>false</code>" です。このオプションは <code><var>options</var></code> プロパティや、 Unicode 拡張キーで指定できます。両方で指定された場合、 <code><var>options</var></code> プロパティの指定が優先されます。</dd> + <dt><code>kf</code></dt> + <dd>大文字と小文字のどちらを先に並べるかを指定します。指定可能な値は "<code>upper</code>", "<code>lower</code>", "<code>false</code>" (ロケールの既定値を使用) です。このオプションは <code><var>options</var></code> プロパティや、 Unicode 拡張キーで指定できます。両方で指定された場合、 <code><var>options</var></code> プロパティの指定が優先されます。</dd> + </dl> + </dd> + <dt><code><var>options</var></code></dt> + <dd> + <p>任意。次のプロパティの一部またはすべてを持つオブジェクトです。</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>ロケール文字列のマッチングに使用するアルゴリズム。指定可能な値は "<code>lookup</code>" と "<code>best fit</code>" で、既定値は "<code>best fit</code>" です。このオプションの詳細については {{jsxref("Global_Objects/Intl", "Intl のページ", "#Locale_negotiation", 1)}}を参照してください。</dd> + <dt><code>usage</code></dt> + <dd>ソート用の比較をするのか、文字列検索用の比較をするのか。指定可能な値は "<code>sort</code>" または "<code>search</code>" で、既定値は "<code>sort</code>" です。</dd> + <dt><code>sensitivity</code></dt> + <dd> + <p>どの程度の文字の違いまでを区別するかです。以下の値を指定可能です。</p> + + <ul> + <li>"<code>base</code>": ベース文字が異なれば、異なる文字であると評価します。 例: <code>a ≠ b</code>、 <code>a = á</code>、 <code>a = A</code></li> + <li>"<code>accent</code>": ベース文字が異なるか、またはアクセントその他の発音区別符号が異なれば、異なる文字であると評価します。 例: <code>a ≠ b</code>、 <code>a ≠ á</code>、 <code>a = A</code></li> + <li>"<code>case</code>": ベース文字が異なるか、ベース文字が同一でも大文字小文字が異なれば、異なる文字であると評価します。 例: <code>a ≠ b</code>、 <code>a = á</code>、 <code>a ≠ A</code></li> + <li>"<code>variant</code>": ベース文字、アクセントその他の発音区別符号、および大文字小文字のいずれかが異なれば、異なる文字であると評価します。他の違いも考慮されるかもしれません。 例: <code>a ≠ b</code>、 <code>a ≠ á</code>、 <code>a ≠ A</code></li> + </ul> + + <p>既定値は、 <code>usage</code> が "<code>sort</code>" の場合は "<code>variant</code>"、 "<code>search</code>"の場合はロケール依存です。</p> + </dd> + <dt><code>ignorePunctuation</code></dt> + <dd>句読点を無視するかどうか。指定可能な値は <code>true</code> または <code>false</code> で、既定値は <code>false</code> です。</dd> + <dt><code>numeric</code></dt> + <dd>"1" < "2" < "10" のように数値として比較を行うかどうかです。可能な値は <code>true</code> および <code>false</code> です。既定値は <code>false</code> です。このオプションは <code><var>options</var></code> プロパティや、 Unicode 拡張キーで指定できます。両方で指定された場合、 <code><var>options</var></code> プロパティの指定が優先されます。実装はこのプロパティに対応することが要件とはされていません。</dd> + <dt><code>caseFirst</code></dt> + <dd>大文字と小文字のどちらを先に並べるかです。指定可能な値は "<code>upper</code>", "<code>lower</code>", "<code>false</code>" (ロケールの既定の動作) です。大文字と小文字のどちらを先に並べるかは <code><var>options</var></code> プロパティでも Unicode 拡張キーでも指定可能です。両方で指定された場合、 <code><var>options</var></code> プロパティの指定が優先されます。実装はこのプロパティに対応することが要件とはされていません。</dd> + </dl> + </dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_Collator" name="Using_Collator">Collator の使用</h3> + +<p>次の例では、文字列が別の文字列の前であるか、後であるか、または同じレベルで発生したのかの様々な可能性のある結果を示しています。</p> + +<pre class="brush: js notranslate">console.log(new Intl.Collator().compare('a', 'c')); // → a negative value +console.log(new Intl.Collator().compare('c', 'a')); // → a positive value +console.log(new Intl.Collator().compare('a', 'a')); // → 0 +</pre> + +<p>上記のコードで示された結果は、ブラウザーやブラウザーのバージョンによって異なる可能性があることに注意してください。これは、値が実装固有のものであるためです。つまり、仕様では前後の値が負と正の値であることだけが要求されています。</p> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-the-intl-collator-constructor', 'Intl.Collator constructor')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Collator.Collator")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><code><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Intl">Intl</a></code></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/collator/compare/index.html b/files/ja/web/javascript/reference/global_objects/intl/collator/compare/index.html new file mode 100644 index 0000000000..947a3a596f --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/collator/compare/index.html @@ -0,0 +1,88 @@ +--- +title: Intl.Collator.prototype.compare +slug: Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare +tags: + - Collator + - Internationalization + - Intl + - JavaScript + - Method + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator.prototype.compare()</code></strong> メソッドは、2つの文字列をこの {{jsxref("Collator")}} オブジェクトのソート順に従って比較します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-collator-prototype-compare.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>collator</var>.compare(<var>string1</var>, <var>string2</var>)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>string1</var></code></dt> + <dt><code><var>string2</var></code></dt> + <dd>互いに比較する文字列です。</dd> +</dl> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>compare</code> ゲッター関数は、 <code>string1</code> と <code>string2</code> をこの {{jsxref("Collator")}} オブジェクトのソート順に従って比較した結果を数値で返します。 <code>string1</code> が <code>string2</code> の前にくる場合は負の値、 <code>string1</code> が <code>string2</code> の後にくる場合は正の値、等しいとみなされる場合は 0 を返します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_compare_for_array_sort" name="Using_compare_for_array_sort">配列の並べ替えにおける compare の使用</h3> + +<p>配列の並べ替えのために <code>compare</code> ゲッター関数を使用します。なお、この関数は、取得元の collator にバインドされているので、直接 {{jsxref("Array.prototype.sort()")}} に渡すことができます。</p> + +<pre class="brush: js notranslate">var a = ['Offenbach', 'Österreich', 'Odenwald']; +var collator = new Intl.Collator('de-u-co-phonebk'); +a.sort(collator.compare); +console.log(a.join(', ')); +// → "Odenwald, Österreich, Offenbach" +</pre> + +<h3 id="Using_compare_for_array_search" name="Using_compare_for_array_search">配列の検索における compare の使用</h3> + +<p>配列内の文字列の検索のために <code>compare</code> ゲッター関数を使用します。</p> + +<pre class="brush: js notranslate">var a = ['Congrès', 'congres', 'Assemblée', 'poisson']; +var collator = new Intl.Collator('fr', { usage: 'search', sensitivity: 'base' }); +var s = 'congres'; +var matches = a.filter(v => collator.compare(v, s) === 0); +console.log(matches.join(', ')); +// → "Congrès, congres" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様書</th> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.collator.prototype.compare', 'Intl.Collator.prototype.compare')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Collator.compare")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Collator", "Intl.Collator")}}</li> + <li>{{jsxref("String.prototype.localeCompare()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/collator/index.html b/files/ja/web/javascript/reference/global_objects/intl/collator/index.html new file mode 100644 index 0000000000..24a3e83d2b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/collator/index.html @@ -0,0 +1,109 @@ +--- +title: Intl.Collator +slug: Web/JavaScript/Reference/Global_Objects/Intl/Collator +tags: + - Class + - Collator + - Internationalization + - Intl + - JavaScript +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Collator +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator</code></strong> オブジェクトは、言語を考慮した文字列の比較を可能にします。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-collator.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/Collator/Collator", "Intl.Collator()")}}</dt> + <dd>新しい <code>Collator</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("Collator.supportedLocalesOf", "Intl.Collator.supportedLocalesOf()")}}</dt> + <dd>指定したロケールのうち、ランタイムの既定のロケールに代替されることなく対応されているものを含む配列を返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("Collator.compare", "Intl.Collator.prototype.compare")}}</dt> + <dd>この {{jsxref("Global_Objects/Collator", "Intl.Collator")}} オブジェクトのソート順に応じて2つの文字列を比較する関数を返します。</dd> + <dt>{{jsxref("Collator.resolvedOptions", "Intl.Collator.prototype.resolvedOptions()")}}</dt> + <dd>ローケルを反映しているプロパティとオブジェクトの初期化中に計算された照合オプションをもった新しいオブジェクトを返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_Collator" name="Using_Collator">Collator の使用</h3> + +<p>次の例では、一方の文字列が他方の文字列の前である場合、後である場合、および同じレベルである場合の比較結果を表示します。</p> + +<pre class="brush: js notranslate">console.log(new Intl.Collator().compare('a', 'c')); // → 負の値 +console.log(new Intl.Collator().compare('c', 'a')); // → 正の値 +console.log(new Intl.Collator().compare('a', 'a')); // → 0 +</pre> + +<p>上記コードの結果は、ブラウザーやブラウザーのバージョンによって異なる可能性がある点に注意してください。というのも前および後を表す数値については、それぞれ負の数および正の数であることだけが仕様によって定めています。具体的な数値は定められていないため、実装ごとに異なる数値になるかもしれません。</p> + +<h3 id="locales_の使用">locales の使用</h3> + +<p>{{jsxref("Collator.prototype.compare()")}} の結果は言語によって異なります。アプリケーションのユーザインターフェイスで使用される言語のソート順を取得するには、 <code><var>locales</var></code> 引数にその言語 (およびフォールバック用の言語も) を指定してください。</p> + +<pre class="brush: js notranslate">// in German, ä sorts with a +console.log(new Intl.Collator('de').compare('ä', 'z')); +// → 負の値 + +// in Swedish, ä sorts after z +console.log(new Intl.Collator('sv').compare('ä', 'z')); +// → 正の値 +</pre> + +<h3 id="Using_options" name="Using_options">options の使用</h3> + +<p>T{{jsxref("Collator.prototype.compare()")}} の結果は <code><var>options</var></code> 引数でカスタマイズできます。</p> + +<pre class="brush: js notranslate">// in German, ä has a as the base letter +console.log(new Intl.Collator('de', { sensitivity: 'base' }).compare('ä', 'a')); +// → 0 + +// in Swedish, ä and a are separate base letters +console.log(new Intl.Collator('sv', { sensitivity: 'base' }).compare('ä', 'a')); +// → 正の値 +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#collator-objects', 'Intl.Collator')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Collator")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><code><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Intl">Intl</a></code></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/collator/resolvedoptions/index.html b/files/ja/web/javascript/reference/global_objects/intl/collator/resolvedoptions/index.html new file mode 100644 index 0000000000..e57ca7a74c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/collator/resolvedoptions/index.html @@ -0,0 +1,87 @@ +--- +title: Intl.Collator.prototype.resolvedOptions() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Collator/resolvedOptions +tags: + - Collator + - Internationalization + - Intl + - JavaScript + - Method + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Collator/resolvedOptions +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator.prototype.resolvedOptions()</code></strong> メソッドは、この {{jsxref("Collator")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトを返します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-collator-prototype-resolvedoptions.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>collator</var>.resolvedOptions()</pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>この {{jsxref("Collator")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトです。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>返されるオブジェクトには以下のプロパティがあります。</p> + +<dl> + <dt><code>locale</code></dt> + <dd>実際に使用したロケールの BCP 47 言語タグ。このロケールにつながる入力 BCP 47 言語タグに Unicode 拡張値が要求された場合、要求されたキーと値のペアのうち、このロケールで対応しているものが <code>locale</code> に含まれます。</dd> + <dt><code>usage</code></dt> + <dt><code>sensitivity</code></dt> + <dt><code>ignorePunctuation</code></dt> + <dd><code>options</code> 引数の同名のプロパティで提供された値、または既定値が入ります。</dd> + <dt><code>collation</code></dt> + <dd><code>locale</code> が対応している場合は、 Unicode 拡張キー <code>"co"</code> を使用して要求された値、そうでなければ <code>"default"</code> です。</dd> + <dt><code>numeric</code></dt> + <dt><code>caseFirst</code></dt> + <dd><code>options</code> 引数の同名のプロパティ、または Unicode 拡張キーの <code>"kn"</code> および <code>"kf"</code> で要求された値、または既定値が入ります。実装がこれらのプロパティに対応していない場合は、省略されます。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_the_resolvedOptions_method" name="Using_the_resolvedOptions_method">resolvedOptions メソッドの使用</h3> + +<pre class="brush: js notranslate">var de = new Intl.Collator('de', { sensitivity: 'base' }) +var usedOptions = de.resolvedOptions(); + +usedOptions.locale; // "de" +usedOptions.usage; // "sort" +usedOptions.sensitivity; // "base" +usedOptions.ignorePunctuation; // false +usedOptions.collation; // "default" +usedOptions.numeric; // false +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様書</th> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.collator.prototype.resolvedoptions', 'Intl.Collator.prototype.resolvedOptions')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Collator.resolvedOptions")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Collator", "Intl.Collator")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/collator/supportedlocalesof/index.html b/files/ja/web/javascript/reference/global_objects/intl/collator/supportedlocalesof/index.html new file mode 100644 index 0000000000..1fd61a49ec --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/collator/supportedlocalesof/index.html @@ -0,0 +1,85 @@ +--- +title: Intl.Collator.supportedLocalesOf() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Collator/supportedLocalesOf +tags: + - Collator + - Internationalization + - Intl + - JavaScript + - Method +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Collator/supportedLocalesOf +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator.supportedLocalesOf()</code></strong> メソッドは、ランタイムの既定のロケールで代替しなくても照合で対応するロケールを含む配列を返します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-collator-prototype-supportedlocalesof.html","shorter")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><code>Intl.Collator.supportedLocalesOf(<var>locales</var>[, <var>options</var>])</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code></dt> + <dd>BCP 47 言語タグを持つ文字列、またはそのような文字列の配列です。 <code>locales</code> 引数の一般的な形式については、 {{jsxref("Global_Objects/Intl", "Intl のページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。</dd> + <dt><code><var>options</var></code></dt> + <dd> + <p>省略可能です。以下のプロパティを持つことがあるオブジェクトです。</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使用するロケールの一致アルゴリズムです。指定可能な値は <code>lookup</code> および <code>best fit</code> で、既定値は <code>best fit</code> です。このオプションの詳細は、 {{jsxref("Global_Objects/IntlIntl", "Intl のページ", "#Locale_negotiation", 1)}}を参照してください。</dd> + </dl> + </dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>指定したロケールタグのサブセットを表す文字列の配列で、ランタイムの既定のロケールで代替する必要なく複数形の書式で対応されているものを含みます。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>locales</code> で指定されている言語タグのサブセットを含む配列を返します。返される言語タグは、ランタイムがロケールの照合に対応しているもので、使用しているロケール一致アルゴリズムが、既定のロケールで代替することなく一致するとみなすものです。</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Using_supportedLocalesOf">Using <code>supportedLocalesOf</code></h3> + +<p>インドネシア語とドイツ語に対応しているもの、バリ語に対応していないランタイムを想定すると、ピンインの照合がインドネシア語では使用されておらず、インドネシアに特化したドイツ語がサポートされている可能性が低いとしても、 <code>supportedLocalesOf</code> はインドネシア語とドイツ語の言語タグを変更せずに返します。これは <code>lookup</code> アルゴリズムの仕様であること注意してください。 <code>best fit</code> マッチャーは、ほとんどのバリ語話者がインドネシア語も理解しているので、インドネシア語がバリ語に適切であると判断し、バリ語の言語タグも返すかもしれません。</p> + +<pre class="brush: js notranslate">var locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +var options = { localeMatcher: 'lookup' }; +console.log(Intl.Collator.supportedLocalesOf(locales, options).join(', ')); +// → "id-u-co-pinyin, de-ID" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様書</th> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.collator.supportedlocalesof', 'Intl.Collator.supportedLocalesOf')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Collator.supportedLocalesOf")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Collator", "Intl.Collator")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html new file mode 100644 index 0000000000..049e69396d --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html @@ -0,0 +1,191 @@ +--- +title: Intl.DateTimeFormat() コンストラクター +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat +tags: + - Constructor + - DateTimeFormat + - Intl + - JavaScript + - Reference + - コンストラクター +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.DateTimeFormat()</code></strong> コンストラクターは、言語に応じた日付と時刻の書式化を可能にするオブジェクトのためのものです。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox">new Intl.DateTimeFormat([<var>locales</var>[, <var>options</var>]])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code> {{optional_inline}}</dt> + <dd> + <p>BCP47 言語タグの文字列、または、そのような文字列の配列です。ブラウザーの既定のロケールを使用するには、この引数を省略するか、 <code>undefined</code> を渡すかしてください。 Unicode 拡張に対応しています (例えば "<code>en-US-u-ca-buddhist</code>" など)。 <code>locales</code> 引数の一般的な形式と解釈は、 {{jsxref("Global_Objects/Intl", "Intl", "#Locale_identification_and_negotiation", 1)}} のページをご覧ください。次の Unicode 拡張キーが利用できます。</p> + + <dl> + <dt><code>nu</code></dt> + <dd>番号方式。使用できる値は次のとおりです。 "<code>arab</code>", "<code>arabext</code>", "<code>bali</code>", "<code>beng</code>", "<code>deva</code>", "<code>fullwide</code>", "<code>gujr</code>", "<code>guru</code>", "<code>hanidec</code>", "<code>khmr</code>", "<code>knda</code>", "<code>laoo</code>", "<code>latn</code>", "<code>limb</code>", "<code>mlym</code>", "<code>mong</code>", "<code>mymr</code>", "<code>orya</code>", "<code>tamldec</code>", "<code>telu</code>", "<code>thai</code>", "<code>tibt</code>"</dd> + <dt><code>ca</code></dt> + <dd>カレンダー。使用できる値は次のとおりです。 "<code>buddhist</code>", "<code>chinese</code>", "<code>coptic</code>", "<code>ethiopia</code>", "<code>ethiopic</code>", "<code>gregory</code>", "<code>hebrew</code>", "<code>indian</code>", "<code>islamic</code>", "<code>iso8601</code>", "<code>japanese</code>", "<code>persian</code>", "<code>roc</code>"</dd> + <dt><code>hc</code></dt> + <dd>時制。使用できる値は次の通りです。 "<code>h11</code>", "<code>h12</code>", "<code>h23</code>", "<code>h24</code>".</dd> + </dl> + </dd> + <dt><code><var>options</var></code> {{optional_inline}}</dt> + <dd> + <p>以下のプロパティの一部またはすべてを持つオブジェクトです。</p> + + <dl> + <dt><code>dateStyle</code></dt> + <dd><code>format()</code> が呼び出された際に使用される日付の書式化スタイルです。利用可能な値は以下のとおりです。 + <ul> + <li>"<code>full</code>"</li> + <li>"<code>long</code>"</li> + <li>"<code>medium</code>"</li> + <li>"<code>short</code>"</li> + </ul> + </dd> + <dt><code>timeStyle</code></dt> + <dd><code>format()</code> が呼び出された際に使用される時刻の書式化スタイルです。利用可能な値は以下のとおりです。 + <ul> + <li>"<code>full</code>"</li> + <li>"<code>long</code>"</li> + <li>"<code>medium</code>"</li> + <li>"<code>short</code>"</li> + </ul> + </dd> + <dt><code>fractionalSecondDigits</code></dt> + <dd><code>format()</code> を呼び出したときに適用する秒の小数点以下の桁数です。有効な値は 0-3 です。</dd> + <dt><code>calendar</code></dt> + <dd>暦です。有効な値は、 "<code>buddhist</code>", "<code>chinese</code>", " <code>coptic</code>", "<code>ethiopia</code>", "<code>ethiopic</code>", "<code>gregory</code>", " <code>hebrew</code>", "<code>indian</code>", "<code>islamic</code>", "<code>iso8601</code>", " <code>japanese</code>", "<code>persian</code>", "<code>roc</code>" です。</dd> + <dt><code>dayPeriod</code></dt> + <dd>日単位の期間の表現の仕方です。有効な値は、 "<code>narrow</code>", "<code>short</code>", " <code>long</code>" です。</dd> + <dt><code>numberingSystem</code></dt> + <dd>命数法です。有効な値は、 "<code>arab</code>", "<code>arabext</code>", " <code>bali</code>", "<code>beng</code>", "<code>deva</code>", "<code>fullwide</code>", " <code>gujr</code>", "<code>guru</code>", "<code>hanidec</code>", "<code>khmr</code>", " <code>knda</code>", "<code>laoo</code>", "<code>latn</code>", "<code>limb</code>", "<code>mlym</code>", " <code>mong</code>", "<code>mymr</code>", "<code>orya</code>", "<code>tamldec</code>", " <code>telu</code>", "<code>thai</code>", "<code>tibt</code>" です。</dd> + <dt><code>localeMatcher</code></dt> + <dd>使用するロケール一致アルゴリズム。利用可能な値は "<code>lookup</code>" と "<code>best fit</code>" です。既定値は "<code>best fit</code>" です。このオプションについての詳細は、 {{jsxref("Global_Objects/Intl", "Intl のページ", "#Locale_negotiation", 1)}}をご覧ください。</dd> + <dt><code>timeZone</code></dt> + <dd>使用するタイムゾーン。実装が認識しなければならない唯一の値は "<code>UTC</code>" です。既定値は、実行時の既定のタイムゾーンです。実装は、 <a href="https://www.iana.org/time-zones">IANA タイムゾーンデータベース</a>のタイムゾーン名、例えば "<code>Asia/Shanghai</code>", "<code>Asia/Kolkata</code>", "<code>America/New_York</code>" なども認識できる場合があります。</dd> + <dt><code>hour12</code></dt> + <dd>12時制を使用するかどうか (24時制に対して)。可能な値は <code>true</code> と <code>false</code> です。既定ではロケールに依存します。このオプションは <code>hc</code> 言語タグや <code>hourCycle</code> オプションと一緒に使用された場合、これらを上書きします。</dd> + <dt><code>hourCycle</code></dt> + <dd>使用する時の周期です。利用可能な値は "<code>h11</code>", "<code>h12</code>", "<code>h23</code>", "<code>h24</code>" です。このオプションは <code>hc</code> 言語タグと一緒に使用された場合はそれを上書きし、両方のオプションが指定されていた場合は <code>hour12</code> オプションが優先されます。</dd> + <dt><code>formatMatcher</code></dt> + <dd>使用する書式一致アルゴリズム。可能な値は "<code>basic</code>" と "<code>best fit</code>" です。既定値は "<code>best fit</code>" です。このプロパティの使用方法については、以下の項を参照してください。</dd> + </dl> + + <p>以下のプロパティは、書式化の出力や、要求された表現で使用する日付や時刻のコンポーネントです。実装は、少なくとも以下のサブセットに対応することが要求されています。</p> + + <ul> + <li><code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code>, <code>hour</code>, <code>minute</code>, <code>second</code></li> + <li><code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code></li> + <li><code>year</code>, <code>month</code>, <code>day</code></li> + <li><code>year</code>, <code>month</code></li> + <li><code>month</code>, <code>day</code></li> + <li><code>hour</code>, <code>minute</code>, <code>second</code></li> + <li><code>hour</code>, <code>minute</code></li> + </ul> + + <p>実装は他のサブセットに対応することもでき、要求はすべての利用可能な表現の中から最適なものを見つけるために交渉します。 <code>formatMatcher</code> プロパティによるこの交渉や選択には2つのアルゴリズムが利用できます。<a href="http://www.ecma-international.org/ecma-402/1.0/#BasicFormatMatcher">完全に定義された "<code>basic</code>" アルゴリズム</a>と、実装に依存した"<code>best fit</code>" アルゴリズムです。</p> + + <dl> + <dt><code>weekday</code></dt> + <dd>曜日の表現です。利用可能な値は以下の通りです。 + <ul> + <li>"<code>long</code>" (例 <code>Thursday</code>)</li> + <li>"<code>short</code>" (例 <code>Thu</code>)</li> + <li>"<code>narrow</code>" (例 <code>T</code>)。ロケールによっては、 narrow 形式が同じ曜日が2つある場合もあります (例 <code>Tuesday</code> の narrow 形式も <code>T</code> です)。</li> + </ul> + </dd> + <dt><code>era</code></dt> + <dd>時代の表現です。利用可能な値は以下の通りです。 + <ul> + <li>"<code>long</code>" (例 <code>Anno Domini</code>, 紀元)</li> + <li>"<code>short</code>" (例 <code>AD</code>)</li> + <li>"<code>narrow</code>" (例 <code>A</code>)</li> + </ul> + </dd> + <dt><code>year</code></dt> + <dd>年の表現です。利用可能な値は以下の通りです。 + <ul> + <li>"<code>numeric</code>" (例 <code>2012</code>)</li> + <li>"<code>2-digit</code>" (例 <code>12</code>)</li> + </ul> + </dd> + <dt><code>month</code></dt> + <dd>月の表現です。利用可能な値は以下の通りです。 + <ul> + <li>"<code>numeric</code>" (例 <code>2</code>)</li> + <li>"<code>2-digit</code>" (例 <code>02</code>)</li> + <li>"<code>long</code>" (例 <code>March</code>)</li> + <li>"<code>short</code>" (例 <code>Mar</code>)</li> + <li>"<code>narrow</code>" (例 <code>M</code>)。ロケールによっては、 narrow 形式が同じ月が2つある場合もあります (例 <code>May</code> の narrow 形式も <code>M</code> です)。</li> + </ul> + </dd> + <dt><code>day</code></dt> + <dd>日の表現です。利用可能な値は以下の通りです。 + <ul> + <li>"<code>numeric</code>" (例 <code>1</code>)</li> + <li>"<code>2-digit</code>" (例 <code>01</code>)</li> + </ul> + </dd> + <dt><code>hour</code></dt> + <dd>時の表現です。利用可能な値は "<code>numeric</code>", "<code>2-digit</code>" です。</dd> + <dt><code>minute</code></dt> + <dd>分の表現です。利用可能な値は "<code>numeric</code>", "<code>2-digit</code>" です。</dd> + <dt><code>second</code></dt> + <dd>秒の表現です。利用可能な値は "<code>numeric</code>", "<code>2-digit</code>" です。</dd> + <dt><code>timeZoneName</code></dt> + <dd>タイムゾーン名の表現です。利用可能な値は以下の通りです。 + <ul> + <li>"<code>long</code>" (例 <code>British Summer Time</code>)</li> + <li>"<code>short</code>" (例 <code>GMT+1</code>)</li> + </ul> + </dd> + </dl> + + <p class="noinclude">日付・時間コンポーネントプロパティの既定値は {{jsxref("undefined")}} ですが、すべてのコンポーネントプロパティが {{jsxref("undefined")}} であった場合、 <code>year</code>, <code>month</code>, <code>day</code> は "<code>numeric</code>" であると仮定されます。</p> + </dd> +</dl> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl-datetimeformat-constructor', 'Intl.DateTimeFormat')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.DateTimeFormat")}}</p> + +<h3 id="Implementation_Progress" name="Implementation_Progress">実装の進捗状況</h3> + +<p>以下の表は、クロスブラウザーの安定性にまだ達していない新機能の日々の実装状況を示しています。このデータは、 JavaScript の標準テストスイートである <a href="https://github.com/tc39/test262">Test262</a> で関連する機能テストをナイトリービルド、または各ブラウザの JavaScript エンジンの最新リリースで実行することで生成されます。</p> + +<div>{{EmbedTest262ReportResultsTable("Intl.DateTimeFormat-datetimestyle")}}</div> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><code><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Intl">Intl</a></code></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html new file mode 100644 index 0000000000..af59293b1f --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html @@ -0,0 +1,113 @@ +--- +title: Intl.DateTimeFormat.prototype.format() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Method + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat.prototype.format()</code></strong> メソッドは、この {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトのロケールと整形オプションに従って日付や時刻を整形します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-format.html", "taller")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>dateTimeFormat</var>.format(<var>date</var>)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>date</var></code></dt> + <dd>整形する日付や時刻です。</dd> +</dl> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>format</code> ゲッター関数は、この {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトのロケールと整形オプションに従って日付や時刻を整形し、文字列に格納します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_format" name="Using_format">format の使用</h3> + +<p><code>format</code> ゲッター関数を使用して単一の日付値を整形します。こちらはセルビアの例です。</p> + +<pre class="brush: js notranslate">var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; +var dateTimeFormat = new Intl.DateTimeFormat('sr-RS', options); +console.log(dateTimeFormat.format(new Date())); +// → "недеља, 7. април 2013." +</pre> + +<h3 id="Using_format_with_map" name="Using_format_with_map">format と map の使用</h3> + +<p><code>format</code> ゲッター関数を使用して、配列内のすべての日付を整形することができます。なお、この関数は供給元である {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map()")}} に渡すことができます。</p> + +<pre class="brush: js notranslate">var a = [new Date(2012, 08), new Date(2012, 11), new Date(2012, 03)]; +var options = { year: 'numeric', month: 'long' }; +var dateTimeFormat = new Intl.DateTimeFormat('pt-BR', options); +var formatted = a.map(dateTimeFormat.format); +console.log(formatted.join('; ')); +// → "setembro de 2012; dezembro de 2012; abril de 2012" +</pre> + +<h3 id="書式化された日付値を固定値と比較することは避ける">書式化された日付値を固定値と比較することは避ける</h3> + +<p>ほとんどの場合、 <code>format()</code> が返す書式は一貫しています。しかし、これは将来的に変更される可能性があり、すべての言語で保証されているわけではありません — 出力のバリエーションは設計上のものであり、仕様上は許容されています。最も注目すべきは、 IE や Edge ブラウザは日付の周りに双方向の制御文字を挿入するため、他のテキストと連結したときに出力テキストが適切に流れることです。</p> + +<p>このことから、 <code>format()</code> の結果と固定値を比較することができると期待してはいけません。</p> + +<pre class="brush: js; example-bad notranslate">let d = new Date("2019-01-01T00:00:00.000000Z"); +let formattedDate = Intl.DateTimeFormat(undefined, { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric' +}).format(d); + +"1.1.2019, 01:00:00" === formattedDate; +// true in Firefox and others +// false in IE and Edge +</pre> + +<div class="blockIndicator note"> +<p><strong>注</strong>: この <a href="https://stackoverflow.com/questions/25574963/ies-tolocalestring-has-strange-characters-in-results">StackOverflow のスレッド</a>に詳細や例があります。</p> +</div> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.datetimeformat.prototype.format', 'Intl.DateTimeFormat.format')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.format")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}</li> + <li>{{jsxref("Date.prototype.toLocaleString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleTimeString()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html new file mode 100644 index 0000000000..39d0d6212e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html @@ -0,0 +1,86 @@ +--- +title: Intl.DateTimeFormat.prototype.formatRange() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange +tags: + - JavaScript + - Method + - Reference + - メソッド +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.DateTimeFormat.prototype.formatRange()</code></strong> は、日付の範囲をもっとも簡明な方法で、 {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトがインスタンス化されたときに提供された <strong><code>locale</code></strong> と <code><strong>options</strong></code> に基づいて書式化します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-formatrange.html", "taller")}}</div> + +<p class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre><code>Intl.DateTimeFormat.prototype.formatRange(<var>startDate, endDate</var>)</code></pre> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_formatRange_usage" name="Basic_formatRange_usage">基本的な <code>formatRange</code> の使用</h3> + +<p>このメソッドは2つの {{jsxref("Date")}} を受け取り、 {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトがインスタンス化されたときに提供された <strong><code>locale</code></strong> と <code><strong>options</strong></code> に基づいて日付の範囲を書式化します。</p> + +<pre class="brush: js">let date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0)); +let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0)); +let date3 = new Date(Date.UTC(2007, 0, 20, 10, 0, 0)); +// > 'Wed, 10 Jan 2007 10:00:00 GMT' +// > 'Wed, 10 Jan 2007 11:00:00 GMT' +// > 'Sat, 20 Jan 2007 10:00:00 GMT' + +let fmt1 = new Intl.DateTimeFormat("en", { + year: '2-digit', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric' +}); +console.log(fmt1.format(date1)); +console.log(fmt1.formatRange(date1, date2)); +console.log(fmt1.formatRange(date1, date3)); +// > '1/10/07, 10:00 AM' +// > '1/10/07, 10:00 – 11:00 AM' +// > '1/10/07, 10:00 AM – 1/20/07, 10:00 AM' + +let fmt2 = new Intl.DateTimeFormat("en", { + year: 'numeric', + month: 'short', + day: 'numeric' +}); +console.log(fmt2.format(date1)); +console.log(fmt2.formatRange(date1, date2)); +console.log(fmt2.formatRange(date1, date3)); +// > 'Jan 10, 2007' +// > 'Jan 10, 2007' +// > 'Jan 10 – 20, 2007' +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td><a href="https://tc39.es/proposal-intl-DateTimeFormat-formatRange/#sec-intl.datetimeformat.prototype.formatRange">Intl.DateTimeFormat.prototype.formatRange</a></td> + <td>Stage 3</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html new file mode 100644 index 0000000000..9659a69883 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html @@ -0,0 +1,83 @@ +--- +title: Intl.DateTimeFormat.prototype.formatRangeToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts +tags: + - Internationalization + - JavaScript + - Localization + - Method + - Reference + - i18n +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts +--- +<p>{{JSRef}}</p> + +<p><strong><code>Intl.DateTimeFormat.prototype.formatRangeToParts()</code></strong> メソッドは、 <code><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/prototype">DateTimeFormat</a></code> フォーマッターで生成される期間の各部品を表すロケール特有のトークンを提供します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-formatrangetoparts.html", "taller")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="notranslate"><code>Intl.DateTimeFormat.prototype.formatRangeToParts(<var>startDate</var>, <var>endDate</var>)</code></pre> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_formatRange_usage" name="Basic_formatRange_usage">基本的な formatRangeToParts の使い方</h3> + +<p>このメソッドは2つの {{jsxref("Date")}} を受け取り、期間を書式化する際の各部品を表すロケール特有のトークンを含む {{jsxref("Array")}} オブジェクトを返します。</p> + +<pre class="brush: js notranslate">let date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0)); +let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0)); +// > 'Wed, 10 Jan 2007 10:00:00 GMT' +// > 'Wed, 10 Jan 2007 11:00:00 GMT' + +let fmt = new Intl.DateTimeFormat("en", { + hour: 'numeric', + minute: 'numeric' +}); + +console.log(fmt.formatRange(date1, date2)); +// > '10:00 – 11:00 AM' + +fmt.formatRangeToParts(date1, date2); +// return value: +// [ +// { type: 'hour', value: '10', source: "startRange" }, +// { type: 'literal', value: ':', source: "startRange" }, +// { type: 'minute', value: '00', source: "startRange" }, +// { type: 'literal', value: ' – ', source: "shared" }, +// { type: 'hour', value: '11', source: "endRange" }, +// { type: 'literal', value: ':', source: "endRange" }, +// { type: 'minute', value: '00', source: "endRange" }, +// { type: 'literal', value: ' ', source: "shared" }, +// { type: 'dayPeriod', value: 'AM', source: "shared" } +// ]</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Intl.DateTimeFormat.formatRange', '#sec-Intl.DateTimeFormat.prototype.formatRangeToParts', 'formatRangeToParts()')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.formatRangeToParts")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl.DateTimeFormat.prototype.formatRange()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html new file mode 100644 index 0000000000..b6a1ea6c3e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html @@ -0,0 +1,241 @@ +--- +title: DateTimeFormat.prototype.formatToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Method + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.DateTimeFormat.prototype.formatToParts()</code></strong> メソッドは、ロケールを意識した <code>DateTimeFormat</code> フォーマッターが生成する文字列のロケールを考慮した書式化を可能にします。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>dateTimeFormat</var>.formatToParts(<var>date</var>)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>date</code> {{optional_inline}}</dt> + <dd>書式化する日付。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>書式化された日付のパーツを含むオブジェクトの {{jsxref("Array")}} です。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>formatToParts()</code> メソッドは、日付文字列のフォーマットをカスタマイズするときに役立ちます。これは、ロケール特有の部分を保持しながら、カスタム文字列を構築できるロケール特有のトークンを含むオブジェクトの {{jsxref("Array")}} を返します。<code>formatToParts()</code> メソッドが返却する構造は、このようになります。</p> + +<pre class="brush: js notranslate">[ + { type: 'day', value: '17' }, + { type: 'weekday', value: 'Monday' } +]</pre> + +<p>渡される可能性がある type は以下のとおりです。</p> + +<dl> + <dt>day</dt> + <dd>日付として使用される文字列。たとえば、 "<code>17</code>"。</dd> + <dt>dayPeriod</dt> + <dd>日付期間として使用される文字列。たとえば、 "<code>AM</code>", "<code>PM</code>", "<code>in the morning</code>", "<code>noon</code>" など。</dd> + <dt>era</dt> + <dd>時代として使用される文字列。たとえば、"<code>BC</code>" や "<code>AD</code>"。</dd> + <dt>fractionalSecond</dt> + <dd>小数点以下の秒として使用される文字列です。例えば "<code>0</code>" や "<code>00</code>" や "<code>000</code>" です。</dd> + <dt>hour</dt> + <dd>時刻として使用される文字列。たとえば "<code>3</code>" や "<code>03</code>"。</dd> + <dt>literal</dt> + <dd>日付や時刻の区切りとして使用される文字列。たとえば "<code>/</code>"、"<code>,</code>"、"<code>o'clock</code>"、"<code>de</code>"。</dd> + <dt>minute</dt> + <dd>分として使用される文字列。たとえば、"<code>00</code>"。</dd> + <dt>month</dt> + <dd>月として使用される文字列。たとえば、"<code>12</code>"。</dd> + <dt>relatedYear</dt> + <dd>カレンダーの表現が year ではなくyearNameである場合、関連する4桁のグレゴリオ暦の年に使用される文字列です。例えば "<code>2019</code>" です。</dd> + <dt>second</dt> + <dd>秒として使用される文字列。たとえば、"<code>07</code>" や "<code>42</code>"。</dd> + <dt>timeZoneName</dt> + <dd>タイムゾーン名として使用される文字列。たとえば、"<code>UTC</code>"。</dd> + <dt>weekday</dt> + <dd>曜日として使用される文字列。たとえば、"<code>M</code>" や "<code>Monday</code>"、"<code>Montag</code>"。</dd> + <dt>year</dt> + <dd>年として使用される文字列。たとえば、"<code>2012</code>" や "<code>96</code>"。</dd> + <dt>yearName</dt> + <dd>関連するコンテキストで yearName に使用される文字列、例えば "<code>geng-zi</code>" など。</dd> +</dl> + +<h2 id="Polyfill" name="Polyfill">ポリフィル</h2> + +<p>この機能のポリフィルは、<a href="https://github.com/zbraniecki/proposal-intl-formatToParts">提案リポジトリ</a>から利用できます。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<p><code>DateTimeFormat</code> は、直接操作できないローカライズされた透過的でない文字列を出力します。</p> + +<pre class="brush: js notranslate">var date = Date.UTC(2012, 11, 17, 3, 0, 42); + +var formatter = new Intl.DateTimeFormat('en-us', { + weekday: 'long', + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + fractionalSecondDigits: 3, + hour12: true, + timeZone: 'UTC' +}); + +formatter.format(date); +// "Monday, 12/17/2012, 3:00:42.000 AM" +</pre> + +<p>しかし、多くのユーザーインターフェイスでは、この文字列の書式をカスタマイズしたいという要望があります。 <code>formatToParts</code> メソッドは、文字列を部品単位で提供することで、 <code>DateTimeFormat</code> フォーマッターによって生成された文字列のロケールを意識した書式設定ができるようになります。</p> + +<pre class="brush: js notranslate">formatter.formatToParts(date); + +// return value: +[ + { type: 'weekday', value: 'Monday' }, + { type: 'literal', value: ', ' }, + { type: 'month', value: '12' }, + { type: 'literal', value: '/' }, + { type: 'day', value: '17' }, + { type: 'literal', value: '/' }, + { type: 'year', value: '2012' }, + { type: 'literal', value: ', ' }, + { type: 'hour', value: '3' }, + { type: 'literal', value: ':' }, + { type: 'minute', value: '00' }, + { type: 'literal', value: ':' }, + { type: 'second', value: '42' }, + { type: 'fractionalSecond', value: '000' }, + { type: 'literal', value: ' ' }, + { type: 'dayPeriod', value: 'AM' } +] +</pre> + +<p>これで情報は個別に利用可能になり、カスタマイズされた方法で再び書式化して連結することができます。例えば、{{jsxref("Array.prototype.map()")}}、<a href="/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions">アロー関数</a>、 <a href="/ja/docs/Web/JavaScript/Reference/Statements/switch">switch 文</a>、<a href="/ja/docs/Web/JavaScript/Reference/Template_literals">テンプレートリテラル</a>、 {{jsxref("Array.prototype.reduce()")}} などを使用しています。</p> + +<pre class="brush: js notranslate">var dateString = formatter.formatToParts(date).map(({type, value}) => { + switch (type) { + case 'dayPeriod': return `<b>${value}</b>`; + default : return value; + } +}).reduce((string, part) => string + part); +</pre> + +<p>これにより、 <code>formatToParts()</code> メソッドを使用する際に、日の部分が太字になります。</p> + +<pre class="brush: js notranslate">console.log(formatter.format(date)); +// "Monday, 12/17/2012, 3:00:42.000 AM" + +console.log(dateString); +// "Monday, 12/17/2012, 3:00:42.000 <b>AM</b>"</pre> + +<h3 id="Named_Years_and_Mixed_calendars" name="Named_Years_and_Mixed_calendars">名前付きの年と混合カレンダー</h3> + +<p>いくつかのケースでは、暦は名前付きの年を使用しています。 例えば、中国やチベットの暦では、60年周期の<a href="https://ja.wikipedia.org/wiki/%E5%B9%B2%E6%94%AF">干支</a>を使用しています。これらの年は、グレゴリオ暦の年と関連付けて識別されます。このような場合、 <code>formatToParts()</code> の結果は、通常は年が存在するはずなのに、年の項目ではなく、4桁のグレゴリオ暦の年を含む relatedYear のエントリを含むことになります。バッグの中の項目を (任意の値で) <code>year</code> に設定すると、年と <code>yearName</code> グレゴリオ暦の <code>relatedYear</code> の両方が得られます。</p> + +<pre class="brush: js notranslate">let opts = { year: "numeric", month: "numeric", day: "numeric" }; +let df = new Intl.DateTimeFormat("zh-u-ca-chinese", opts); +df.formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42)); + +// return value +[ + { type: 'relatedYear', value: '2012' }, + { type: 'literal', value: '年' }, + { type: 'month', value: '十一月' }, + { type: 'day', value: '4' } +] +</pre> + +<p><code>year</code> オプションがバッグ内で設定されていない場合 (任意の値に設定されている場合)、結果には <code>relatedYear</code> のみが含まれます。</p> + +<pre class="brush: js notranslate">let df = new Intl.DateTimeFormat("zh-u-ca-chinese"); +df.formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42)); + +// 返値 +[ + { type: 'relatedYear', value: '2012' }, + { type: 'literal', value: '年' }, + { type: 'month', value: '十一月' }, + { type: 'day', value: '4' } +] +</pre> + +<p><code>year</code> を出力したい場合は、 <code>.format()</code> は一般的にこれらを並べて表示することができます。</p> + +<pre class="brush: js notranslate">let df = new Intl.DateTimeFormat("zh-u-ca-chinese", {year: "numeric"}); +df.format(Date.UTC(2012, 11, 17, 3, 0, 42)); + +// 返値 +2012壬辰年</pre> + +<p>これにより、ロケールとカレンダーを両方の <code>format</code> で混在させることも可能になります。</p> + +<pre class="brush: js notranslate">let df = new Intl.DateTimeFormat("en-u-ca-chinese", {year: "numeric"}); +let date = Date.UTC(2012, 11, 17, 3, 0, 42); +df.format(date); + +// 返値 +2012(ren-chen) +</pre> + +<p>および <code>formatToParts</code> の場合</p> + +<pre class="brush: js notranslate">let opts = {month: 'numeric', day: 'numeric', year: "numeric"}; +let df = new Intl.DateTimeFormat("en-u-ca-chinese", opts); +let date = Date.UTC(2012, 11, 17, 3); +df.formatToParts(date) + +// 返値 +[ + { type: 'month', value: '11' }, + { type: 'literal', value: '/' }, + { type: 'day', value: '4' }, + { type: 'literal', value: '/' }, + { type: 'relatedYear', value: '2012' } +] +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.DateTimeFormat.prototype.formatToParts', 'Intl.DateTimeFormat.prototype.formatToParts')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.formatToParts")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> + <li>{{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format")}}</li> + <li>{{jsxref("Date.prototype.toLocaleString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleTimeString()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html new file mode 100644 index 0000000000..0c9a663a52 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html @@ -0,0 +1,195 @@ +--- +title: Intl.DateTimeFormat +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat +tags: + - Class + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.DateTimeFormat</code></strong> オブジェクトは、言語に応じた日付と時刻の書式化を可能にするオブジェクトのためのコンストラクターです。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/DateTimeFormat/DateTimeFormat", "Intl.DateTimeFormat()")}}</dt> + <dd>新しい <code>DateTimeFormat</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("DateTimeFormat.supportedLocalesOf", "Intl.DateTimeFormat.supportedLocalesOf()")}}</dt> + <dd>指定されたロケールのうち、実行時の既定のロケールにフォールバックせずに対応されるものを配列に収めて返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format()")}}</dt> + <dd>ロケールおよびこの {{jsxref("DateTimeFormat", "DateTimeFormat")}} オブジェクトの書式化オプションに則って日付を書式化するゲッター関数です。</dd> + <dt>{{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}</dt> + <dd>オブジェクトの {{jsxref("Array")}} を返し、これは専用のロケールを意識した書式で使用することができる部品内の数値文字列を表します。</dd> + <dt>{{jsxref("DateTimeFormat.resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}</dt> + <dd>ローケルを反映しているプロパティとオブジェクトの初期化中に計算された照合オプションをもった新しいオブジェクトを返します。</dd> + <dt>{{jsxref("DateTimeFormat.formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}}</dt> + <dd>このメソッドは2つの <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/">Date</a> を受け取り、 {{jsxref("DateTimeFormat", "DateTimeFormat")}} インスタンスを生成する際に指定されたロケールとオプションに基づいて、最も簡潔な方法で日付の範囲を書式化します。</dd> + <dt>{{jsxref("DateTimeFormat.formatRangeToParts", "Intl.DateTimeFormat.prototype.formatRangeToParts()")}}</dt> + <dd>このメソッドは2つの <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/">Date</a> を受け取り、書式化された日付の範囲の各部分を表すロケール固有のトークンを含むオブジェクトの配列を返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_DateTimeFormat" name="Using_DateTimeFormat">DateTimeFormat の使用</h3> + +<p>基本的に、ロケールを指定せずに使用すると、 <code>DateTimeFormat</code> は既定のロケールとオプションを使用します。</p> + +<pre class="brush: js notranslate">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); + +// toLocaleString without arguments depends on the implementation, +// the default locale, and the default time zone +console.log(new Intl.DateTimeFormat().format(date)); +// → "12/19/2012" if run with en-US locale (language) and time zone America/Los_Angeles (UTC-0800) +</pre> + +<h3 id="Using_locales" name="Using_locales">locales の使用</h3> + +<p>この例では、ローカライズされた日付と時刻の形式のバリエーションの一部示しています。アプリケーションのユーザーインターフェイスで使用される言語のフォーマットを取得するには、 <code>locales</code> 引数を使用して、その言語 (およびおそらくいくつかのフォールバック言語) を指定してください。</p> + +<pre class="brush: js notranslate">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); + +// Results below use the time zone of America/Los_Angeles (UTC-0800, Pacific Standard Time) + +// US English uses month-day-year order +console.log(new Intl.DateTimeFormat('en-US').format(date)); +// → "12/19/2012" + +// British English uses day-month-year order +console.log(new Intl.DateTimeFormat('en-GB').format(date)); +// → "19/12/2012" + +// Korean uses year-month-day order +console.log(new Intl.DateTimeFormat('ko-KR').format(date)); +// → "2012. 12. 19." + +// Arabic in most Arabic speaking countries uses real Arabic digits +console.log(new Intl.DateTimeFormat('ar-EG').format(date)); +// → "١٩<span dir="rtl">/١٢/٢٠١٢</span>" + +// for Japanese, applications may want to use the Japanese calendar, +// where 2012 was the year 24 of the Heisei era +console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date)); +// → "24/12/19" + +// when requesting a language that may not be supported, such as +// Balinese, include a fallback language, in this case Indonesian +console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date)); +// → "19/12/2012" +</pre> + +<h3 id="Using_options" name="Using_options">options の使用</h3> + +<p>日付と時刻の書式は <code>options</code> 引数を使用してカスタマイズできます。</p> + +<pre class="brush: js notranslate">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200)); + +// request a weekday along with a long date +var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; +console.log(new Intl.DateTimeFormat('de-DE', options).format(date)); +// → "Donnerstag, 20. Dezember 2012" + +// an application may want to use UTC and make that visible +options.timeZone = 'UTC'; +options.timeZoneName = 'short'; +console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +// → "Thursday, December 20, 2012, GMT" + +// sometimes you want to be more precise +options = { + hour: 'numeric', minute: 'numeric', second: 'numeric', + timeZone: 'Australia/Sydney', + timeZoneName: 'short' +}; +console.log(new Intl.DateTimeFormat('en-AU', options).format(date)); +// → "2:00:00 pm AEDT" + +// sometimes you want to be very precise +options.fractionalSecondDigits = 3; +console.log(new Intl.DateTimeFormat('en-AU', options).format(date)); +// → "2:00:00.200 pm AEDT" + + +// sometimes even the US needs 24-hour time +options = { + year: 'numeric', month: 'numeric', day: 'numeric', + hour: 'numeric', minute: 'numeric', second: 'numeric', + hour12: false, + timeZone: 'America/Los_Angeles' +}; +console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +// → "12/19/2012, 19:00:00" + + +// to specify options but use the browser's default locale, use 'default' +console.log(new Intl.DateTimeFormat('default', options).format(date)); +// → "12/19/2012, 19:00:00" + +// sometimes it's helpful to include the period of the day +options = {hour: "numeric", dayPeriod: "short"}; +console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +// → 10 at night +</pre> + +<p>The used calendar and numbering formats can also be set independently via <code>options</code> arguments:</p> + +<pre class="brush: js notranslate">var options = {calendar: 'chinese', numberingSystem: 'arab'}; +var dateFormat = new Intl.DateTimeFormat('default', options); +var usedOptions = dateFormat.resolvedOptions(); + +console.log(usedOptions.calendar); +// → "chinese" + +console.log(usedOptions.numberingSystem); +// → "arab" + +console.log(usedOptions.timeZone); +// → "America/New_York" (the users default timezone) +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#datetimeformat-objects', 'Intl.DateTimeFormat')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Global_Objects/Intl", "Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html new file mode 100644 index 0000000000..bf782a0664 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html @@ -0,0 +1,87 @@ +--- +title: Intl.DateTimeFormat.prototype +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/prototype +tags: + - DateTimeFormat + - Internationalization + - JavaScript + - Property + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.DateTimeFormat.prototype</code></strong> プロパティは、 {{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}} コンストラクターに対するプロトタイプオブジェクトを表します。</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>Intl.DateTimeFormat</code> インスタンスの解説については {{jsxref("DateTimeFormat")}} を確認して下さい。</p> + +<p>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} インスタンスは <code>Intl.DateTimeFormat.prototype</code> から継承します。プロトタイプオブジェクトへの変更はすべての {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} インスタンスによって継承されます。</p> + +<h2 id="Properties" name="Properties">プロパティ</h2> + +<dl> + <dt><code>Intl.DateTimeFormat.prototype.constructor</code></dt> + <dd>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} への参照です。</dd> +</dl> + +<h2 id="Methods" name="Methods">メソッド</h2> + +<dl> + <dt>{{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format()")}}</dt> + <dd>ロケールおよびこの {{jsxref("DateTimeFormat", "DateTimeFormat")}} オブジェクトの書式化オプションに則って日付を書式化するゲッター関数です。</dd> + <dt>{{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}</dt> + <dd>Returns an {{jsxref("Array")}} of objects representing the date string in parts that can be used for custom locale-aware formatting.</dd> + <dt>{{jsxref("DateTimeFormat.resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}</dt> + <dd>ローケルを反映しているプロパティとオブジェクトの初期化中に計算されたオプションをもった新しいオブジェクトを返します。</dd> + <dt>{{jsxref("DateTimeFormat.formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}}</dt> + <dd>This method receives two <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/">Dates</a> and formats the date range in the most concise way based on the locale and options provided when instantiating {{jsxref("DateTimeFormat", "DateTimeFormat")}}.</dd> + <dt>{{jsxref("DateTimeFormat.formatRangeToParts", "Intl.DateTimeFormat.prototype.formatRangeToParts()")}}</dt> + <dd>This method receives two <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/">Dates</a> and returns an Array of objects containing the locale-specific tokens representing each part of the formatted date range.</dd> +</dl> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.DateTimeFormat.prototype', 'Intl.DateTimeFormat.prototype')}}</td> + <td>{{Spec2('ES Int Draft')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ES Int 2.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}</td> + <td>{{Spec2('ES Int 2.0')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.prototype")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html new file mode 100644 index 0000000000..4e28ab0347 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html @@ -0,0 +1,95 @@ +--- +title: Intl.DateTimeFormat.prototype.resolvedOptions() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Method + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Collator.prototype.resolvedOptions()</code></strong> メソッドは、この {{jsxref("Collator")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトを返します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-resolvedoptions.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><var>dateTimeFormat</var>.resolvedOptions()</pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>この {{jsxref("DateTimeFormat")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトです。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>返されるオブジェクトには以下のプロパティがあります。</p> + +<dl> + <dt><code>locale</code></dt> + <dd>実際に使用したロケールの BCP 47 言語タグ。このロケールにつながる入力 BCP 47 言語タグに Unicode 拡張値が要求された場合、要求されたキーと値のペアのうち、このロケールで対応しているものが <code>locale</code> に含まれます。</dd> + <dt><code>calendar</code></dt> + <dd>例: "gregory"</dd> + <dt><code>numberingSystem</code></dt> + <dd>Unicode 拡張キーの <code>"ca"</code> および <code>"nu"</code> で要求された値、または既定値が入ります。</dd> + <dt><code>timeZone</code></dt> + <dd><code>options</code> 引数の同名のプロパティで要求された値です。提供された値がなければ {{jsxref("undefined")}} (ランタイムの既定のタイムゾーン) です。警告: アプリケーションは {{jsxref("undefined")}} が返されることに依存しないでください。将来のバージョンではランタイムの既定のタイムゾーンを識別する {{jsxref("String")}} 値が返されるようになる可能性があるからです。</dd> + <dt><code>hour12</code></dt> + <dd><code>options</code> 引数の同名のプロパティで要求された値、または既定値が入ります。</dd> + <dt><code>weekday</code></dt> + <dt><code>era</code></dt> + <dt><code>year</code></dt> + <dt><code>month</code></dt> + <dt><code>day</code></dt> + <dt><code>hour</code></dt> + <dt><code>minute</code></dt> + <dt><code>second</code></dt> + <dt><code>timeZoneName</code></dt> + <dd><code>options</code> 引数の対応するプロパティと、選択したロケールでの日付時刻の書式設定に利用可能な組み合わせや表現との間で、書式のマッチングを行った結果の値。これらのプロパティの中には、対応するコンポーネントが書式化された出力では表現されないものもあります。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_the_resolvedOptions_method" name="Using_the_resolvedOptions_method">resolvedOptions メソッドの使用</h3> + +<pre class="brush: js notranslate">var germanFakeRegion = new Intl.DateTimeFormat('de-XX', { timeZone: 'UTC' }); +var usedOptions = germanFakeRegion.resolvedOptions(); + +usedOptions.locale; // "de" +usedOptions.calendar; // "gregory" +usedOptions.numberingSystem; // "latn" +usedOptions.timeZone; // "UTC" +usedOptions.month; // "numeric" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様書</th> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.datetimeformat.prototype.resolvedoptions', 'Intl.DateTimeFormat.prototype.resolvedOptions')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.resolvedOptions")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html new file mode 100644 index 0000000000..0be4ec7300 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html @@ -0,0 +1,128 @@ +--- +title: Intl.DateTimeFormat.supportedLocalesOf() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf +tags: + - DateTimeFormat + - Internationalization + - JavaScript + - Method + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf +--- +<div>{{JSRef("Global_Objects", "DateTimeFormat", "Intl,Collator,NumberFormat")}}</div> + +<h2 id="概要">概要</h2> + +<p>ランタイムのデフォルトローケルに戻る必要なしでフォーマットしている日時でサポートしている提供されているローケルを含んでいる配列を返します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code>Intl.DateTimeFormat.supportedLocalesOf(<var>locales</var>[, <var>options</var>])</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>locales</code></dt> + <dd>BCP47言語タグの文字列、そのような文字列の配列。 <code>locales</code>引数の一般的な形式に対して、{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_identification_and_negotiation", 1)}}を確かめて下さい。</dd> + <dt><code>options</code></dt> + <dd> + <p>オプション。次のプロパティを持つオブジェクト:</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使っているローケルマッチングアルゴリズム。利用可能な値は<code>"lookup"</code>、<code>"best fit"</code>。デフォルトでは <code>"best fit"</code>。このオプションについての情報のために、{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}}を確かめて下さい。</dd> + </dl> + </dd> +</dl> + +<h2 id="説明">説明</h2> + +<p><code>locales</code>で提供されている言語タグのサブセットを持つ配列を返します。返される言語タグは、ランタイムがローケルマッチングアルゴリズムを使って考慮してフォーマットしている日時でのローケルをサポートしていてるので、デフォルトローケルに戻る必要はありません。</p> + +<h2 id="例">例</h2> + +<h3 id="例_supportedLocalesOfを使う">例: <code>supportedLocalesOf</code>を使う</h3> + +<p>日時のフォーマットで、バリ語ではなく、インドネシア語とドイツ語をサポートしているランタイムを仮定すると、<code>supportedLocalesOf</code>はインドネシア語とドイツ語の言語タグを返します。ピンインは日時のフォーマットには適切ではなくインドネシア語では使われません。インドネシアの特定のドイツ語はサポートされそうにもありません。 <code>"lookup"</code>アルゴリズムの指定に注意して下さい。<code>"best fit"</code>はインドネシア語はバリ語に対して、十分にふさわしいと決定するかもしれません。というのも、 ほとんどのバリの人はインドネシア語も理解するからです。それゆえバリ言語タグも同様に返します。</p> + +<pre class="brush: js">var locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +var options = { localeMatcher: 'lookup' }; +console.log(Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(', ')); +// → "id-u-co-pinyin, de-ID" +</pre> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-12.2.2', 'Intl.DateTimeFormat.supportedLocalesOf')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>機能</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>基本サポート</td> + <td>{{CompatChrome("24")}}</td> + <td>{{CompatGeckoDesktop("29")}}</td> + <td>{{CompatIE("11")}}</td> + <td>{{CompatOpera("15")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>機能</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>基本サポート</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome("26")}}</td> + <td>{{CompatNo}}<br> + {{bug("864843")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="関連情報">関連情報</h2> + +<ul> + <li>{{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/displaynames/index.html b/files/ja/web/javascript/reference/global_objects/intl/displaynames/index.html new file mode 100644 index 0000000000..2c29a952d4 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/displaynames/index.html @@ -0,0 +1,154 @@ +--- +title: Intl.DisplayNames +slug: Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +tags: + - Class + - DisplayNames + - Internationalization + - Intl + - JavaScript + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.DisplayNames</code></strong> オブジェクトは、言語、地域、文字体系の表示名の一貫した翻訳を可能にするオブジェクトのコンストラクターです。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-displaynames.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/DisplayNames/DisplayNames", "Intl.DisplayNames()")}}</dt> + <dd><code>Intl.DisplayNames</code> オブジェクトを作成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("Intl/DisplayNames/supportedLocalesOf", "Intl.DisplayNames.supportedLocalesOf()")}}</dt> + <dd>提供されたロケールのうち、ランタイムのデフォルトロケールにフォールバックすることなくサポートされているロケールを含む配列を返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("Intl/DisplayNames/of", "Intl.DisplayNames.prototype.of()")}}</dt> + <dd>このメソッドは <code>code</code> を受け取り、<a href="#"><code>Intl.DisplayNames</code></a> をインスタンス化したときに指定したロケールとオプションに基づく文字列を返します。</dd> + <dt>{{jsxref("Intl/DisplayNames/resolvedOptions", "Intl.DisplayNames.prototype.resolvedOptions()")}}</dt> + <dd>オブジェクトの初期化時に計算されたロケールや書式設定のオプションを反映したプロパティを持つ新しいオブジェクトを返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Region_Code_Display_Names" name="Region_Code_Display_Names">国 (地域) の表示名</h3> + +<p>ロケールを指定した <code>Intl.DisplayNames</code> を作成し、国 (地域) コードの表示名を取得する方法です。</p> + +<pre class="brush: js notranslate">// 英語の地域名を表示 +let regionNames = new Intl.DisplayNames(['en'], {type: 'region'}); +regionNames.of('419'); // "Latin America" +regionNames.of('BZ'); // "Belize" +regionNames.of('US'); // "United States" +regionNames.of('BA'); // "Bosnia & Herzegovina" +regionNames.of('MM'); // "Myanmar (Burma)" + +// 繁体字中国語での地域名を表示 +regionNames = new Intl.DisplayNames(['zh-Hant'], {type: 'region'}); +regionNames.of('419'; // "拉丁美洲" +regionNames.of('BZ'); // "貝里斯" +regionNames.of('US'); // "美國" +regionNames.of('BA'); // "波士尼亞與赫塞哥維納" +regionNames.of('MM'); // "緬甸"</pre> + +<h3 id="Language_Display_Names" name="Language_Display_Names">言語の表示名</h3> + +<p>ロケールを指定した <code>Intl.DisplayNames</code> を作成し、言語-文字体系-国 (地域) の一連の表示名を取得する方法です。</p> + +<pre class="brush: js notranslate">// 英語の言語名を表示 +let languageNames = new Intl.DisplayNames(['en'], {type: 'language'}); +languageNames.of('fr'); // "French" +languageNames.of('de'); // "German" +languageNames.of('fr-CA'); // "Canadian French" +languageNames.of('zh-Hant'); // "Traditional Chinese" +languageNames.of('en-US'); // "American English" +languageNames.of('zh-TW'); // "Chinese (Taiwan)"] + +// 繁体字中国語での言語名を表示 +languageNames = new Intl.DisplayNames(['zh-Hant'], {type: 'language'}); +languageNames.of('fr'); // "法文" +languageNames.of('zh'); // "中文" +languageNames.of('de'); // "德文"</pre> + +<h3 id="Script_Code_Display_Names" name="Script_Code_Display_Names">文字体系コードの表示名称</h3> + +<p>ロケールを指定した <code>Intl.DisplayNames</code> を作成し、文字体系の表示名を取得する方法です。</p> + +<pre class="brush: js notranslate">// 英語の文字体系名を表示 +let scriptNames = new Intl.DisplayNames(['en'], {type: 'script'}); +// Get script names +scriptNames.of('Latn'); // "Latin" +scriptNames.of('Arab'); // "Arabic" +scriptNames.of('Kana'); // "Katakana" + +// 繁体字中国語での文字体系名を表示 +scriptNames = new Intl.DisplayNames(['zh-Hant'], {type: 'script'}); +scriptNames.of('Latn'); // "拉丁文" +scriptNames.of('Arab'); // "阿拉伯文" +scriptNames.of('Kana'); // "片假名"</pre> + +<h3 id="Currency_Code_Display_Names" name="Currency_Code_Display_Names">通貨コードの表示名称</h3> + +<p>ロケールを指定した <code>Intl.DisplayNames</code> を作成し、通貨の表示名を取得する方法です。</p> + +<pre class="brush: js notranslate">// 英語の通貨名を表示 +let currencyNames = new Intl.DisplayNames(['en'], {type: 'currency'}); +// Get currency names +currencyNames.of('USD'); // "US Dollar" +currencyNames.of('EUR'); // "Euro" +currencyNames.of('TWD'); // "New Taiwan Dollar" +currencyNames.of('CNY'); // "Chinese Yuan" + +// 繁体字中国語の通貨名を表示 +currencyNames = new Intl.DisplayNames(['zh-Hant'], {type: 'currency'}); +currencyNames.of('USD'); // "美元" +currencyNames.of('EUR'); // "歐元" +currencyNames.of('TWD'); // "新台幣" +currencyNames.of('CNY'); // "人民幣"</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Intl.DisplayNames', '#intl-displaynames-objects', 'DisplayNames')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.DisplayNames")}}</p> +</div> + +<h3 id="Implementation_Progress" name="Implementation_Progress">実装の進捗</h3> + +<p>以下の表は、クロスブラウザーの安定性に達していない、新しい機能に対する日次の実装ステータスを提供します。データは、JavaScript の標準テストスイート、Nightly ビルド、または各ブラウザーの最新の JavaScript エンジンを使用して、<a href="https://github.com/tc39/test262">Test262</a> 内で適切な機能テストを実行することにより生成されます。</p> + +<p>{{EmbedTest262ReportResultsTable("Intl.DisplayNames")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/getcanonicallocales/index.html b/files/ja/web/javascript/reference/global_objects/intl/getcanonicallocales/index.html new file mode 100644 index 0000000000..1d85e32e87 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/getcanonicallocales/index.html @@ -0,0 +1,74 @@ +--- +title: Intl.getCanonicalLocales() +slug: Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales +tags: + - Internationalization + - Intl + - JavaScript + - Method +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.getCanonicalLocales()</code></strong> メソッドは、正規のロケール名を含む配列を返します。重複は省略され、要素は構造的に有効な言語タグとして検証されます。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-getcanonicallocales.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate">Intl.getCanonicalLocales(locales)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>locales</code></dt> + <dd>標準ロケール名を取得するための {{jsxref("String")}} 値リスト。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>正規のロケール名を含む配列です。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_getCanonicalLocales" name="Using_getCanonicalLocales">getCanonicalLocales の使用</h3> + +<pre class="brush: js notranslate">Intl.getCanonicalLocales('EN-US'); // ["en-US"] +Intl.getCanonicalLocales(['EN-US', 'Fr']); // ["en-US", "fr"] + +Intl.getCanonicalLocales('EN_US'); +// RangeError:'EN_US' is not a structurally valid language tag +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.getcanonicallocales', 'Intl.getCanonicalLocales')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.getCanonicalLocales")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat.supportedLocalesOf", "Intl.NumberFormat.supportedLocalesOf()")}}</li> + <li>{{jsxref("DateTimeFormat.supportedLocalesOf", "Intl.DateTimeFormat.supportedLocalesOf()")}}</li> + <li>{{jsxref("Collator.supportedLocalesOf", "Intl.Collator.supportedLocalesOf()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/index.html b/files/ja/web/javascript/reference/global_objects/intl/index.html new file mode 100644 index 0000000000..f6c08e0a31 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/index.html @@ -0,0 +1,133 @@ +--- +title: Intl +slug: Web/JavaScript/Reference/Global_Objects/Intl +tags: + - Internationalization + - Intl + - JavaScript + - Namespace + - 名前空間 + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl</code></strong> オブジェクトは、 ECMAScript の国際化 API の名前空間で、言語に依存した文字列の比較、数値フォーマット、日付フォーマットを提供します。 <strong><code>Intl</code></strong> オブジェクトは、いくつかのコンストラクターに加え、国際化コンストラクターや他の言語に関する関数に共通する機能へのアクセスを提供します。</p> + +<h2 id="Properties" name="Properties">プロパティ</h2> + +<dl> + <dt>{{jsxref("Global_Objects/Collator", "Intl.Collator")}}</dt> + <dd>言語に依存した文字列の比較を可能にするオブジェクトである collator のためのコンストラクター。</dd> + <dt>{{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}</dt> + <dd>言語に依存した日時の書式化を可能にするオブジェクトのためのコンストラクター。</dd> + <dt>{{jsxref("Global_Objects/ListFormat", "Intl.ListFormat")}}</dt> + <dd>言語に依存したリストの書式化を可能にするオブジェクトのためのコンストラクター。</dd> + <dt>{{jsxref("Global_Objects/Locale", "Intl.Locale")}}</dt> + <dd>Unicode ロケール識別子を表すオブジェクトのためのコンストラクター。</dd> + <dt>{{jsxref("Global_Objects/NumberFormat", "Intl.NumberFormat")}}</dt> + <dd>言語に依存した数値フォーマットを可能にするオブジェクトのためのコンストラクター。</dd> + <dt>{{jsxref("Global_Objects/PluralRules", "Intl.PluralRules")}}</dt> + <dd>複数形を意識した書式化や複数形の言語規則を可能にするオブジェクトのためのコンストラクター。</dd> + <dt>{{jsxref("Global_Objects/RelativeTimeFormat", "Intl.RelativeTimeFormat")}}</dt> + <dd>言語を意識した相対時刻の書式化を可能にするオブジェクトのためのコンストラクター。</dd> +</dl> + +<h2 id="Methods" name="Methods">メソッド</h2> + +<dl> + <dt>{{jsxref("Intl.getCanonicalLocales()")}}</dt> + <dd>正規のロケール名を返すメソッド。</dd> +</dl> + +<h2 id="Locale_identification_and_negotiation" name="Locale_identification_and_negotiation">ロケールの識別とネゴシエーション</h2> + +<p>国際化コンストラクターや他のコンストラクターの言語を意識したメソッド (<a href="#See_also">関連情報</a>に記載) は、ロケールを識別して実際に使用するものを決定するために共通のパターンを使用しています。これらはすべて、 <code>locales</code> と <code>options</code> の引数を受け取り、 <code>options.localeMatcher</code> プロパティで指定したアルゴリズムを使用して 要求されたロケールと対応しているロケールとのネゴシエーションを行います。</p> + +<h3 id="locales_argument" name="locales_argument">locales 引数</h3> + +<p><code>locales</code> 引数は、 <a href="http://tools.ietf.org/html/rfc5646">BCP 47 言語タグ</a>を保持している文字列か、そのような言語タグの配列でなければなりません。 <code>locales</code> 引数が与えられていなかったり、 undefined であったりした場合は、実行時の既定のロケールが使用されます。</p> + +<p>BCP 47 言語タグは、言語と、少なくとも主たる言語コードを含んでいます。ほとんどのよくある形式では、すべてハイフンで区切られたサブタグを、言語コード、文字体系コード、国または地域コードの順で含んでいます。タグは大文字小文字を区別しませんが、文字体系コードでは先頭が大文字で残りは小文字、国または地域コードでは大文字、その他はすべて小文字が推奨されています。</p> + +<p>例:</p> + +<ul> + <li><code>"hi"</code>: ヒンディー語 (主たる言語)。</li> + <li><code>"de-AT"</code>: オーストリアで使用されているドイツ語 (主たる言語と国コード)。</li> + <li><code>"zh-Hans-CN"</code>: 中国で使用されている簡体字で書かれる中国語 (主たる言語と文字体系と国コード)。</li> +</ul> + +<p>言語、文字体系、国 (地域)、 (まれに使用される) 変化形を識別する BCP 47 言語タグのサブタグは <a href="http://www.iana.org/assignments/language-subtag-registry">IANA Language Subtag Registry</a> で調べられます。</p> + +<p>BCP 47 はまた、拡張を認めており、そのうちの一つ <code>"u"</code> (Unicode) 拡張は、 JavaScript の国際化機能にとって重要です。それは、{{jsxref("Collator")}}, {{jsxref("NumberFormat")}}, {{jsxref("DateTimeFormat")}} オブジェクトのロケール固有の動作のカスタマイズを要求するために使用することができます。</p> + +<ul> + <li><code>"de-DE-u-co-phonebk"</code>: ドイツ語のソート順の電話帳変化形を使用します。このソート順では、ウムラウト付きの母音を、 ä → ae, ö → oe, ü → ue のように、ウムラウトの付かない母音二文字に展開したものと見なした順で並べ替えします。</li> + <li><code>"th-TH-u-nu-thai"</code>: 数値書式で、タイの数字 (๐, ๑, ๒, ๓, ๔, ๕, ๖, ๗, ๘, ๙) を使用します。</li> + <li><code>"ja-JP-u-ca-japanese"</code>: 日時書式で和暦を使用します。すなわち、2013年は平成25年として表現されます。</li> + <li><code>"en-GB-u-ca-islamic"</code>: イギリス英語でイスラム暦 (Hijri) を使用します。グレゴリオ暦で2017年10月14日は、 Hijri 暦で 24 Muharram, 1439 です。</li> +</ul> + +<p>BCP 47 拡張タグは <a href="https://unicode.org/repos/cldr/trunk/common/bcp47/">Unicode CLDR Project</a> にあります。</p> + +<h3 id="Locale_negotiation" name="Locale_negotiation">ロケールネゴシエーション</h3> + +<p><code>locales</code> 引数は、すべての Unicode 拡張を除去した後、アプリケーションからの優先順位付き要求として解釈されます。ランタイムは、利用可能なローケルと比較し、利用可能なロケールのうち最適なものを選びます。マッチングアルゴリズムは二種類あります。 "<code>lookup</code>" マッチャーは、<a href="http://tools.ietf.org/html/rfc4647#section-3.4">BCP 47</a> で指定された Lookup アルゴリズムに従います。 "<code>best fit</code>" マッチャーでは、ランタイムが少なくとも、あるいは場合によっては、 Lookup アルゴリズムの結果よりもリクエストに適合したロケールを提供します。アプリケーションが <code>locales</code> 引数を提供しなかった場合や、リクエストに一致するロケールをランタイムが持っていなかった場合は、ランタイムの既定のロケールが使用されます。マッチャーは、 <code>options</code> 引数のプロパティを使って選択することができます (後述)。</p> + +<p>ネゴシエーションにより選択された言語タグが Unicode 拡張の部分文字列を持っているとき、その拡張はここで、構築されたオブジェクトや関数の振る舞いをカスタマイズするために使われます。それぞれのコンストラクターや関数は、 Unicode 拡張用のキーのごく一部分のみ対応しており、また、対応する値は、多くの場合言語タグに依存します。例えば、 "<code>co</code>" キー (コレクション)は、 {{jsxref("Collator")}} だけが対応しており、そのキーに対する "<code>phonebk</code>" の値はドイツ語だけが対応しています。</p> + +<h3 id="options_argument" name="options_argument">options 引数</h3> + +<p><code>options</code> 引数は、コンストラクターや関数ごとに異なるプロパティをもつオブジェクトである必要があります。 <code>options</code> 引数が与えられなかった場合、または、未定義の場合、すべてのプロパティに対して既定値が使用されます。</p> + +<p>言語を意識するすべてのコンストラクターや関数が対応しているプロパティが一つあります。 <code>localeMatcher</code> プロパティで、この値は "<code>lookup</code>" または "<code>best fit</code>" の文字列である必要があり、上記のとけーるマッチングアルゴリズムのうちから一つを選択します。</p> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#intl-object', 'Intl')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>導入: <a href="https://norbertlindenberg.com/2012/12/ecmascript-internationalization-api/index.html">The ECMAScript Internationalization API</a></li> + <li>コンストラクター + <ul> + <li>{{jsxref("Collator", "Intl.Collator")}}</li> + <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> + <li>{{jsxref("ListFormat", "Intl.ListFormat")}}</li> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> + <li>{{jsxref("PluralRules", "Intl.PluralRules")}}</li> + <li>{{jsxref("RelativeTimeFormat", "Intl.RelativeTimeFormat")}}</li> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + </ul> + </li> + <li>メソッド + <ul> + <li>{{jsxref("String.prototype.localeCompare()")}}</li> + <li>{{jsxref("Number.prototype.toLocaleString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleDateString()")}}</li> + <li>{{jsxref("Date.prototype.toLocaleTimeString()")}}</li> + </ul> + </li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/listformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/listformat/index.html new file mode 100644 index 0000000000..08be4d24aa --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/listformat/index.html @@ -0,0 +1,104 @@ +--- +title: Intl.ListFormat +slug: Web/JavaScript/Reference/Global_Objects/Intl/ListFormat +tags: + - Class + - Experimental + - Internationalization + - Intl + - JavaScript + - ListFormat + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/ListFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.ListFormat</code></strong> オブジェクトは、言語特有のリストを利用可能にするコンストラクターです。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-listformat.html", "taller")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/ListFormat/ListFormat", "Intl.ListFormat()")}}</dt> + <dd>新しい <code>ListFormat</code> オブジェクトを作成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("ListFormat.supportedLocalesOf", "Intl.ListFormat.supportedLocalesOf()")}}</dt> + <dd>指定したロケールのうち、ランタイムの既定のロケールに代替されることなく対応しているものを含む配列を返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("ListFormat.prototype.format", "Intl.ListFormat.prototype.format()")}}</dt> + <dd>言語固有の形式の文字列を返して,列挙要素を表示します。</dd> + <dt>{{jsxref("ListFormat.prototype.formatToParts", "Intl.ListFormat.prototype.formatToParts()")}}</dt> + <dd>ロケールを考慮した方法で値のリストを整形するために使用できる、さまざまな部分を表すオブジェクトの配列を返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="format_の使用">format の使用</h3> + +<p>次の例では、英語を使用するリストのフォーマッターを生成する方法を示します。</p> + +<pre class="brush: js notranslate">const list = ['Motorcycle', 'Bus', 'Car']; + + console.log(new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }).format(list)); +// > Motorcycle, Bus and Car + + console.log(new Intl.ListFormat('en-GB', { style: 'short', type: 'disjunction' }).format(list)); +// > Motorcycle, Bus or Car + + console.log(new Intl.ListFormat('en-GB', { style: 'narrow', type: 'unit' }).format(list)); +// > Motorcycle Bus Car +</pre> + +<h3 id="Using_formatToParts" name="Using_formatToParts">formatToParts の使用</h3> + +<p>次の例では、整形済みの部分を返すリストフォーマッターを生成する方法を示します。</p> + +<pre class="brush: js notranslate">const list = ['Motorcycle', 'Bus', 'Car']; +console.log(new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }).formatToParts(list)); + +// [ { "type": "element", "value": "Motorcycle" }, +// { "type": "literal", "value": ", " }, +// { "type": "element", "value": "Bus" }, +// { "type": "literal", "value": ", and " }, +// { "type": "element", "value": "Car" } ]; +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Intl.ListFormat', '#listformat-objects', 'ListFormat')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.ListFormat")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/basename/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/basename/index.html new file mode 100644 index 0000000000..5157d8c0bd --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/basename/index.html @@ -0,0 +1,75 @@ +--- +title: Intl.Locale.prototype.baseName +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName +tags: + - Internationalization + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Locale.prototype.baseName</code></strong> プロパティは、 <code>Locale</code> の文字列表現の部分文字列を返し、そこには <code>Locale</code> についての中核情報が含まれています。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>{{jsxref("Locale", "Intl.Locale")}} オブジェクトは、解析されたロケールとそのロケールのオプションを表します。 <code>baseName</code> プロパティは、ロケールに関する基本的な情報を、完全なデータ文字列の部分文字列の形で返します。具体的には、このプロパティは言語を含む部分文字列を返し、文字体系や地域があればそれも返します。</p> + +<p><code>baseName</code> は <code>言語 ["-" 文字体系] ["-" 地域] *("-" variant)</code> の形で <a href="https://www.unicode.org/reports/tr35/#Identifiers">unicode_language_id grammar</a> の部分文字列を返します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_Example" name="Basic_Example">基本的な例</h3> + +<pre class="brush: js">let myLoc = new Intl.Locale("fr-Latn-CA"); // ロケールをカナダのフランス語に設定 +console.log(myLoc.toString()); // "fr-Latn-CA-u-ca-gregory" と表示 +console.log(myLoc.baseName); // "fr-Latn-CA" と表示</pre> + +<h3 id="入力文字列のオプション付きの例">入力文字列のオプション付きの例</h3> + +<pre class="brush: js">// 言語を日本語、地域を日本に設定する。 + +// カレンダーをグレゴリオ暦、時制を24時制にする +let japan = new Intl.Locale("ja-JP-u-ca-gregory-hc-24"); +console.log(japan.toString()); // "ja-JP-u-ca-gregory-hc-h24" と表示 +console.log(japan.baseName); // "ja-JP" と表示</pre> + +<h3 id="入力文字列を上書きするオプション付きの例">入力文字列を上書きするオプション付きの例</h3> + +<pre class="brush: js">// 入力文字列は言語がオランダ語、地域がベルギーであることを示していますが、 + +// ただし、オプションオブジェクトで地域を上書きしており、オランダに設定しています +let dutch = new Intl.Locale("nl-Latn-BE", {region: "NL"}); + +console.log(dutch.baseName); // "nl-Latn-NL" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.baseName')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.baseName")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/calendar/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/calendar/index.html new file mode 100644 index 0000000000..4df268ee41 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/calendar/index.html @@ -0,0 +1,159 @@ +--- +title: Intl.Locale.prototype.calendar +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar +tags: + - Internationalization + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Locale.prototype.calendar</code></strong> プロパティは、 <code>Locale</code> で使用される暦の種類を返すアクセサープロパティです。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>calendar</code> プロパティは <code>Locale</code> の一部、 <code>Locale</code> の暦を示す部分を返します。世界の大部分はグレゴリオ暦を使用していますが、世界各地で使用されている地域暦もいくつかあります。以下の表に、有効な Unicode 暦キー文字列をすべて示します。</p> + +<h3 id="Unicode_calendar_keys" name="Unicode_calendar_keys">Unicode 暦キー</h3> + +<table class="standard-table"> + <caption>Unicode 暦キー</caption> + <thead> + <tr> + <th scope="col">Calendar key (name)</th> + <th scope="col">説明</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>buddhist</code></td> + <td>タイの仏教暦</td> + </tr> + <tr> + <td><code>chinese</code></td> + <td>古来の中国の暦</td> + </tr> + <tr> + <td><code>coptic</code></td> + <td>コプト暦</td> + </tr> + <tr> + <td><code>dangi</code></td> + <td>古来の韓国の暦</td> + </tr> + <tr> + <td><code>ethioaa</code></td> + <td>Ethiopic calendar, Amete Alem (epoch approx. 5493 B.C.E)</td> + </tr> + <tr> + <td><code>ethiopic</code></td> + <td>Ethiopic calendar, Amete Mihret (epoch approx, 8 C.E.)</td> + </tr> + <tr> + <td><code>gregory</code></td> + <td>グレゴリオ暦</td> + </tr> + <tr> + <td><code>hebrew</code></td> + <td>古来のヘブライ暦</td> + </tr> + <tr> + <td><code>indian</code></td> + <td>インド暦</td> + </tr> + <tr> + <td><code>islamic</code></td> + <td>イスラム暦</td> + </tr> + <tr> + <td><code>islamic-umalqura</code></td> + <td>Islamic calendar, Umm al-Qura</td> + </tr> + <tr> + <td><code>islamic-tbla</code></td> + <td>Islamic calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - astronomical epoch)</td> + </tr> + <tr> + <td><code>islamic-civil</code></td> + <td>Islamic calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - civil epoch)</td> + </tr> + <tr> + <td><code>islamic-rgsa</code></td> + <td>Islamic calendar, Saudi Arabia sighting</td> + </tr> + <tr> + <td><code>iso8601</code></td> + <td>ISO カレンダー (ISO 8601 カレンダーの曜日規則を使用したグレゴリオ暦)</td> + </tr> + <tr> + <td><code>japanese</code></td> + <td>日本の皇紀</td> + </tr> + <tr> + <td><code>persian</code></td> + <td>ペルシャ暦</td> + </tr> + <tr> + <td><code>roc</code></td> + <td>中華民国暦</td> + </tr> + <tr> + <td> + <div class="blockIndicator warning"><code>islamicc</code> 暦は非推奨です。 <code>islamic-civil</code> を使用してください。</div> + + <p><code>islamicc</code></p> + </td> + <td>Civil (algorithmic) Arabic calendar</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Adding_a_calendar_in_the_Locale_string" name="Adding_a_calendar_in_the_Locale_string">ロケール文字列へのカレンダーの追加</h3> + +<p>暦は、ロケールキーの「拡張キー」に該当します。これらのキーは、ロケールに関するデータを追加するもので、拡張子 <code>-u</code> を使用してロケール識別子に追加します。したがって、 {{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターに渡される初期のロケール識別子文字列に暦の種類を追加することができます。暦の種類を追加するには、まず文字列に <code>-u</code> 拡張を追加します。次に、暦の種類を追加することを示すために <code>-ca</code> 拡張を追加します。最後に、暦を文字列に追加します。</p> + +<pre class="brush: js">let frBuddhist = new Intl.Locale("fr-FR-u-ca-buddhist"); +console.log(frBuddhist.calendar); // "buddhist" と表示</pre> + +<h3 id="Adding_a_calendar_with_a_configuration_object" name="Adding_a_calendar_with_a_configuration_object">構成オブジェクトによる暦の追加</h3> + +<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、カレンダーを含めた拡張の種類を渡すために使用することができます。構成オブジェクトの <code>calendar</code> プロパティを望みの暦の値に設定し、コンストラクターに渡します。</p> + +<pre class="brush: js">let frBuddhist = new Intl.Locale("fr-FR", {calendar: "buddhist"}); +console.log(frBuddhist.calendar); // "buddhist" と表示 +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.calendar')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.calendar")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li><a href="https://www.unicode.org/reports/tr35/#UnicodeCalendarIdentifier">Unicode 暦識別子</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/casefirst/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/casefirst/index.html new file mode 100644 index 0000000000..6f337ab869 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/casefirst/index.html @@ -0,0 +1,92 @@ +--- +title: Intl.Locale.prototype.caseFirst +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.caseFirst</code></strong> プロパティは、ロケールの照合規則に大文字・小文字を考慮するかどうかを返すアクセサプロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>ロケールの照合規則は、そのロケールでの文字列の並び順を決定するために用いられます。ロケールによっては、照合処理で文字の大文字・小文字を使用する場合があります。この追加ルールは、 {{jsxref("Locale", "Locale")}} の <code>caseFirst</code> プロパティで表現することができます。</p> + +<p><code>caseFirst</code> プロパティには下記の表にある通り、3種類の値を指定することができます。</p> + +<h3 id="caseFirst_values" name="caseFirst_values"><code>caseFirst</code> の値</h3> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">値</th> + <th scope="col">説明</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>upper</code></td> + <td>大文字は小文字よりも前に並べられます。</td> + </tr> + <tr> + <td><code>lower</code></td> + <td>小文字は大文字よりも前に並べられます。</td> + </tr> + <tr> + <td><code>false</code></td> + <td>大文字・小文字で特別な並べ替えはしません。</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Setting_the_caseFirst_value_via_the_locale_string" name="Setting_the_caseFirst_value_via_the_locale_string">ロケール文字列による <code>caseFirst</code> 値の設定</h3> + +<p><a href="https://www.unicode.org/reports/tr35/" rel="noopener">Unicode ロケール文字列仕様書</a>では、 <code>caseFirst</code> が表す値は <code>kf</code> キーに対応します。 <code>kf</code> はロケール文字列の「拡張子サブタグ」として扱われます。これらのサブタグは、ロケールに関するデータを追加するもので、 <code>-u</code> 拡張を使用してロケール識別子に追加されます。つまり、 <code>caseFirst</code> の値は、 <code>Locale</code> コンストラクターに渡される初期のロケール識別子文字列に追加することができます。 <code>caseFirst</code> の値を追加するには、まず文字列に <code>-u</code> 拡張キーを追加します。次に、照合順序の型を追加することを示すために <code>-kf</code> 拡張キーを追加します。最後に、 <code>caseFirst</code> の値を文字列に追加します。</p> + +<pre class="brush: js">let caseFirstStr = new Intl.Locale("fr-Latn-FR-u-kf-upper"); +console.log(caseFirstStr.caseFirst); // "upper" と表示</pre> + +<h3 id="Setting_the_caseFirst_value_via_the_configuration_object_argument" name="Setting_the_caseFirst_value_via_the_configuration_object_argument">構成オブジェクト引数による caseFirst の値の設定</h3> + +<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、拡張の種類を渡すために使用することができます。構成オブジェクトの <code>caseFirst</code> プロパティを望みの <code>caseFirst</code> の値に設定し、コンストラクターに渡します。</p> + +<pre class="brush: js">let caseFirstObj= new Intl.Locale("en-Latn-US", {caseFirst: "lower"}); +console.log(us12hour.caseFirst); // "lower" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.caseFirst')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.caseFirst")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li><a href="https://github.com/unicode-org/cldr/blob/master/common/bcp47/collation.xml#L49">Unicode case first collation spec</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/collation/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/collation/index.html new file mode 100644 index 0000000000..d2dad676cb --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/collation/index.html @@ -0,0 +1,166 @@ +--- +title: Intl.Locale.prototype.collation +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.collation</code></strong> プロパティは、 <code>Locale</code> の<a href="https://www.unicode.org/reports/tr35/tr35-collation.html#CLDR_Collation">照合種別</a>を返すアクセサープロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>照合とは、文字列を並べ替える処理のことです。検索クエリの結果からデータベース内のレコードの順序付けまで、文字列を特定の順序に並べ替えて配置しなければならない場合に使用されます。文字列を順番に配置するという考えは些細なことのように思えるかもしれませんが、順序の考え方は地域や言語によって異なることがあります。 <code>collation</code> プロパティは、 JavaScript プログラマーが特定のロケールで使用される照合種別に簡単にアクセスできるようにすることを助けます。</p> + +<p>利用可能な照合種別は下記の表にあります。 <a href="https://github.com/unicode-org/cldr/blob/2dd06669d833823e26872f249aa304bc9d9d2a90/common/bcp47/collation.xml">Unicode 照合仕様書</a> から引用したものです。</p> + +<h3 id="Valid_collation_types" name="Valid_collation_types">有効な照合種別</h3> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">照合種別</th> + <th scope="col">説明</th> + </tr> + </thead> + <tbody> + <tr> + <td>big5han</td> + <td>ラテン文字はピンイン順、漢字は big5 文字セット順 (中国語で使用)</td> + </tr> + <tr> + <td>compat</td> + <td>前の版の順序で、互換性のため</td> + </tr> + <tr> + <td>dict</td> + <td>辞書形式の順序 (シンハラ語など)</td> + </tr> + <tr> + <td> + <div class="blockIndicator warning"> + <p><code>direct</code> 照合順は非推奨です。使用しないでください。</p> + </div> + + <p>direct</p> + </td> + <td>バイナリコードポイント順 (ヒンズー語で使用)</td> + </tr> + <tr> + <td>ducet</td> + <td>既定の Unicode 照合順で、要素表順</td> + </tr> + <tr> + <td>emoji</td> + <td>絵文字に推奨の順序</td> + </tr> + <tr> + <td>eor</td> + <td>ヨーロッパ語の順序の規則</td> + </tr> + <tr> + <td>gb2312</td> + <td>ラテン文字はピンイン順、漢字は gb2312han 順 (中国語で使用)</td> + </tr> + <tr> + <td>phonebk</td> + <td>電話帳形式の順序 (ドイツ語など)</td> + </tr> + <tr> + <td>phonetic</td> + <td>発音順 (発音に基づく順序)</td> + </tr> + <tr> + <td>pinyin</td> + <td>ラテン文字と漢字はピンイン順 (中国語で使用)</td> + </tr> + <tr> + <td>reformed</td> + <td>リフォーム順 (スウェーデン語など)</td> + </tr> + <tr> + <td>search</td> + <td>文字列検索のための特殊な照合種別</td> + </tr> + <tr> + <td>searchjl</td> + <td>韓国語の頭文字子音検索用の特殊な照合種別</td> + </tr> + <tr> + <td>standard</td> + <td>各言語の既定の照合順</td> + </tr> + <tr> + <td>stroke</td> + <td>ラテン文字はピンイン順、漢字は画数順 (中国語で使用)</td> + </tr> + <tr> + <td>trad</td> + <td>歴史的な形の順序 (スペイン語など)</td> + </tr> + <tr> + <td>unihan</td> + <td>ラテン文字はピンイン順、漢字は Unihan 部首画数順 (中国語で使用)</td> + </tr> + <tr> + <td>zhuyin</td> + <td> + <p>ラテン文字はピンイン順、漢字とパパラモフォは注音順 (中国語で使用)</p> + </td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<p>他のロケールのサブタグと同様、照合種別はロケール文字列やコンストラクターの構成オブジェクトの引数で {{jsxref("Locale", "Intl.Locale")}} オブジェクトに追加することができます。</p> + +<h3 id="Adding_a_collation_type_via_the_locale_string" name="Adding_a_collation_type_via_the_locale_string">ロケール文字列による照合種別の追加</h3> + +<p><a href="https://www.unicode.org/reports/tr35/">Unicode ロケール文字列仕様書</a>では、照合種別はロケールキーの「拡張子サブタグ」となります。これらのサブタグは、ロケールに関するデータを追加するもので、 <code>-u</code> 拡張を使用してロケール識別子に追加されます。つまり、照合種別は、ロケールのコンストラクターに渡される初期のロケール識別子文字列に追加することができます。照合種別を追加するには、まず文字列に <code>-u</code> 拡張を追加します。次に、照合順序の型を追加することを示すために <code>-co</code> 拡張を追加します。最後に、照合順序を文字列に追加します。</p> + +<pre class="brush: js">let stringColl = new Intl.Locale("en-Latn-US-u-co-emoji"); +console.log(stringColl.collation); // "emoji" と表示 +</pre> + +<h3 id="Adding_a_collation_type_via_the_configuration_object_argument" name="Adding_a_collation_type_via_the_configuration_object_argument">構成オブジェクト引数による照合種別の追加</h3> + +<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、これには照合種別を含む任意の拡張の種類をいくつか含めることができます。構成オブジェクトの <code>collation</code> プロパティを任意の照合種別に設定し、コンストラクターに渡します。</p> + +<pre class="brush: js">let configColl = new Intl.Locale("en-Latn-US", {collation: "emoji"}); +console.log(configColl.collation); // "emoji" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.collation')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Locale.collation")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/hourcycle/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/hourcycle/index.html new file mode 100644 index 0000000000..1d68f033ed --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/hourcycle/index.html @@ -0,0 +1,96 @@ +--- +title: Intl.Locale.prototype.hourCycle +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.hourCycle</code></strong> プロパティは、ロケールで使用される時刻保持書式の規則を返すアクセサープロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>世界中で使用されている時刻保持規則 (時制) には、主に12時制と24時制の2つの種類があります。 <code>hourCycle</code> プロパティを使用すると、 JavaScript のプログラマーが特定のロケールで使用されている時制に簡単にアクセスできるようになります。他の追加ロケールデータと同様に、時制種別は<a href="https://www.unicode.org/reports/tr35/#u_Extension">拡張サブタグ</a>であり、ロケール文字列に含まれるデータを拡張したものです。時制種別には、以下の表にある通り、いくつかの異なる値を設定することができます。</p> + +<h3 id="有効な時制種別">有効な時制種別</h3> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">時制種別</th> + <th scope="col">説明</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>h12</code></td> + <td>1–12を使用する時制で、パターンの 'h' に対応します。12時制で、正子は午前12:00から始まります。</td> + </tr> + <tr> + <td><code>h23</code></td> + <td>0–23を使用する時制で、パターンの 'H' に対応します。24時制で、正子は0:00から始まります。</td> + </tr> + <tr> + <td><code>h11</code></td> + <td>0–11を使用する時制で、パターンの 'K' に対応します。12時制で、正子は午前0:00から始まります。</td> + </tr> + <tr> + <td><code>h24</code></td> + <td>1–24を使用する時制で、パターンの 'k' に対応します。24時制で、正子は24:00から始まります。</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<p>これらの例は、時制データを {{jsxref("Locale", "Locale")}} オブジェクトに追加する方法を示しています。</p> + +<h3 id="Setting_the_numeric_value_via_the_locale_string" name="Setting_the_numeric_value_via_the_locale_string">ロケール文字列による時制の追加</h3> + +<p><a href="https://www.unicode.org/reports/tr35/" rel="noopener">Unicode ロケール文字列仕様書</a>では、時制はロケール文字列の「拡張サブタグ」です。これらのサブタグはロケールについての追加データであり、拡張キー <code>-u</code> を使用してロケール識別子に追加されます。このようして、 <code>numeric</code> の値を {{jsxref("Locale/Locale", "Locale")}} コンストラクターに渡される初期のロケール識別子文字列に追加することができます。時制種別の値を設定するには、まず文字列に <code>-u</code> 拡張キーを追加します。次に、 <code>-hc</code> 拡張キーを追加して、時制種別の値を追加していることを示します。最後に、時制種別の値を文字列に追加します。</p> + +<pre class="brush: js">let ja24hour = new Intl.Locale("ja-JP-u-hc-h23"); +console.log(ja24hour.hourCycle); // "h23" と表示</pre> + +<h3 id="Adding_an_hour_cycle_via_the_configuration_object_argument" name="Adding_an_hour_cycle_via_the_configuration_object_argument">構成オブジェクト引数から時制を追加</h3> + +<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、これには時制種別を含む任意の拡張の種類をいくつか含めることができます。構成オブジェクトの <code>hourCycle</code> プロパティを任意の時制種別に設定し、コンストラクターに渡します。</p> + +<pre class="brush: js">let us12hour = new Intl.Locale("en-US", {hourCycle: "h12"}); +console.log(us12hour.hourCycle); // "h12" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.hourCycle')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.hourCycle")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li><a href="https://www.unicode.org/reports/tr35/#UnicodeHourCycleIdentifier">Unicode 時間周期拡張キー仕様書</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/index.html new file mode 100644 index 0000000000..d11507595d --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/index.html @@ -0,0 +1,104 @@ +--- +title: Intl.Locale +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale +tags: + - Class + - Internationalization + - Intl + - JavaScript + - Reference + - クラス + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale</code></strong> オブジェクトは、 Unicode ロケール識別子を表す Intl オブジェクトの標準組み込みプロパティです。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-locale.html")}}</div> + +<h2 id="Description" name="Description">解説</h2> + +<p><code><strong>Intl.Locale</strong></code> オブジェクトは、 Unicode ロケールをより簡単に操作できるようにするために作成されました。 Unicode は、ロケールを<em>ロケール識別子</em>と呼ばれる文字列で表します。ロケール識別子は、<em>言語識別子</em>と<em>拡張タグ</em>から構成されます。言語識別子はロケールの中核となるもので、<em>言語</em>、<em>文字体系</em>、<em>地域サブタグ</em>から構成されます。ロケールに関する追加情報は、オプションの拡張タグに格納されます。<em>拡張タグ</em>には、暦の種類や時計の種類、数値表記法の種類などのロケールに関する情報が格納されています。</p> + +<p>従来、 Intl API は Unicode と同様に文字列を使用してロケールを表していました。これはシンプルで軽量な解決策であり、うまく機能します。しかし、 Locale クラスを追加することで、言語、文字体系、地域、拡張タグの解析や操作が容易になります。</p> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Locale/Locale", "Intl.Locale()")}}</dt> + <dd>新しい <code>Locale</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Properties" name="Properties">プロパティ</h2> + +<dl> + <dt><code>Intl.Locale.prototype</code></dt> + <dd><code>Locale</code> コンストラクターのプロトタイプオブジェクトです。</dd> +</dl> + +<h2 id="Instance_properties" name="Instance_properties">インスタンスプロパティ</h2> + +<dl> + <dt>{{jsxref("Locale/baseName", "Intl.Locale.prototype.baseName")}}</dt> + <dd>この <code>Locale</code> に関する基本的な情報を、完全なデータ文字列の部分文字列の形で返します。</dd> + <dt>{{jsxref("Locale/calendar", "Intl.Locale.prototype.calendar")}}</dt> + <dd>このロケールの暦年を示す <code>Locale</code> の部分を返します。</dd> + <dt>{{jsxref("Locale/caseFirst", "Intl.Locale.prototype.caseFirst")}}</dt> + <dd>ロケールの照合規則に大文字・小文字を考慮しているかどうかを返します。</dd> + <dt>{{jsxref("Locale/collation", "Intl.Locale.prototype.collation")}}</dt> + <dd>この <code>Locale</code> の照合の種類を返します。これは、ロケールの規則に従って文字列を並べ替えるために使用します。</dd> + <dt>{{jsxref("Locale/hourCycle", "Intl.Locale.prototype.hourCycle")}}</dt> + <dd>このロケールが使用している時刻保持書式の規約を返します。</dd> + <dt>{{jsxref("Locale/language", "Intl.Locale.prototype.language")}}</dt> + <dd>このロケールに関連づけられた言語を返します。</dd> + <dt>{{jsxref("Locale/numberingSystem", "Intl.Locale.prototype.numberingSystem")}}</dt> + <dd>このロケールが使用している数値表記法を返します。</dd> + <dt>{{jsxref("Locale/numeric", "Intl.Locale.prototype.numeric")}}</dt> + <dd>このロケールが数字に対して特殊な照合順序を持っているかどうかを返します。</dd> + <dt>{{jsxref("Locale/region", "Intl.Locale.prototype.region")}}</dt> + <dd>このロケールに関連付けられた世界の地域 (通常は国) を返します。</dd> + <dt>{{jsxref("Locale/script", "Intl.Locale.prototype.script")}}</dt> + <dd>このロケールで使われている特定の言語を書く際に使用する文字体系を返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("Locale/minimize", "Intl.Locale.prototype.minimize()")}}</dt> + <dd>既存の値に基づいて、ロケールの言語、表記法、地域の最も可能性の高い値を取得します。</dd> + <dt>{{jsxref("Locale/maximize", "Intl.Locale.prototype.maximize()")}}</dt> + <dd>既存の値に基づいて、ロケールの言語、表記法、地域の最も可能性の高い値を取得します。</dd> + <dt>{{jsxref("Locale/toString", "Intl.Locale.prototype.toString()")}}</dt> + <dd>このロケールの完全なロケール識別子文字列を返します。</dd> +</dl> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#locale-objects')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Locale")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="https://github.com/zbraniecki/Intl.js/tree/intllocale">The Intl.Locale Polyfill</a></li> + <li><a href="https://www.unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers">Unicode locale identifiers spec</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/language/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/language/index.html new file mode 100644 index 0000000000..7996d348df --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/language/index.html @@ -0,0 +1,67 @@ +--- +title: Intl.Locale.prototype.language +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/language +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/language +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.language</code></strong> プロパティは、ロケールに関連付けられた言語を返すアクセサープロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>言語はロケールの中核的な特徴の一つです。 Unicode 仕様書では、ロケールの言語識別子を言語と地域を合わせたものとして扱います (イギリス英語とアメリカ英語などの方言や変化形を区別するためです)。 {{jsxref("Locale", "Locale")}} の <code>language</code> プロパティは、ロケールの言語サブタグを厳密に返します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Setting_the_script_in_the_locale_identifer_string_argument" name="Setting_the_script_in_the_locale_identifer_string_argument">ロケール識別子の文字列引数で言語を設定</h3> + +<p>有効な Unicode 言語識別子となるためには、文字列は言語サブタグで始めなければなりません。 {{jsxref("Locale/Locale", "Locale")}} コンストラクターの主要な引数には、有効な Unicode ロケール識別子がなければならないので、コンストラクターを使用する際には必ず言語サブタグを持つ識別子を渡さなければなりません。</p> + +<pre class="brush: js">let langStr = new Intl.Locale("en-Latn-US"); + +console.log(langStr.language); // "en" と表示</pre> + +<h3 id="Setting_the_script_via_the_configuration_object" name="Setting_the_script_via_the_configuration_object">構成オブジェクトにより言語を上書き</h3> + +<p>言語サブタグは指定する必要がありますが、 {{jsxref("Locale/Locale", "Locale")}} コンストラクターは構成オブジェクトを取り、これを用いて言語サブタグを上書きすることができます。</p> + +<pre class="brush: js">let langObj = new Intl.Locale("en-Latn-US", {language: "es"}); + +console.log(langObj.language); // "es" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.language')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.language")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Locale")}}</li> + <li><a href="https://www.unicode.org/reports/tr35/#unicode_language_subtag_validity">Unicode 言語サブタグ仕様書</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/locale/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/locale/index.html new file mode 100644 index 0000000000..8624c2d4ff --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/locale/index.html @@ -0,0 +1,61 @@ +--- +title: Intl.Locale() コンストラクター +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale +tags: + - Constructor + - Intl + - JavaScript + - Locale + - Reference + - コンストラクター + - ロケール +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale</code></strong> コンストラクターは、 Intl オブジェクトの標準組み込みプロパティで、 Unicode ロケール識別子を表します。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-locale.html")}}</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox">new Intl.Locale(<var>tag</var> [, <var>options</var>])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>tag</var></code></dt> + <dd>Unicode ロケール識別子の文字列です。</dd> + <dt><code><var>options</var></code></dt> + <dd>ロケールの構成を含むオブジェクトです。キーは Unicode ロケールタグで、値は有効な Unicode タグ値です。</dd> +</dl> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl-locale-constructor')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Locale.Locale")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="https://github.com/zbraniecki/Intl.js/tree/intllocale">The Intl.Locale Polyfill</a></li> + <li><a href="https://www.unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers">Unicode locale identifiers spec</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html new file mode 100644 index 0000000000..1e2848c7e3 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html @@ -0,0 +1,79 @@ +--- +title: Intl.Locale.prototype.maximize() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize +tags: + - Internationaliztion + - Intl + - JavaScript + - Method + - Prototype + - Reference + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.maximize()</code></strong> メソッドは、既存の値に基づいてロケールの言語、表記法、地域の最も可能性の近い値を取得します。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-locale-prototype-maximize.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code><em>locale</em>.maximize()</code></pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>{{jsxref("Locale", "Locale")}} インスタンスで、 <code>baseName</code> プロパティが、 <a href="https://www.unicode.org/reports/tr35/#Likely_Subtags">Add Likely Subtags</a> アルゴリズムが <em>{{jsxref("Locale/baseName", "locale.baseName")}}</em> に対して実行された結果になったものを返します。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>不完全な言語識別子をもとに、最も可能性の高いロケール言語識別子サブタグを識別できると便利な場合があります。 Add Likely Subtags アルゴリズムはこの機能を提供してくれます。例えば、言語識別子 "en" が与えられた場合、アルゴリズムは "en-Latn-US" を返すことになります。英語はラテン文字でしか書けませんし、世界最大の英語圏の国であるアメリカで使われている可能性が高いからです。この機能は、 <code>maximize()</code> メソッドを介して JavaScript プログラマーに提供されています。 <code>maximize()</code> は、<a href="https://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions" rel="noopener">言語識別子</a>を構成する主要なサブタグのうち言語サブ、表記法、地域の各サブタグにのみ影響を与えます。ロケール識別子の "-u" の後にあるその他のサブタグは拡張サブタグと呼ばれ、 <code>maximize()</code> メソッドの影響を受けません。これらのサブタグの例としては、 {{jsxref("Locale/hourCycle", "Locale.hourCycle")}}, {{jsxref("Locale/calendar", "Locale.calendar")}}, {{jsxref("Locale/numeric", "Locale.numeric")}} などがあります。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js">let myLocale = new Intl.Locale("ja", {hourCycle: "h24", calendar: "gregory"}); +console.log(myLocale.baseName); // "ja" と表示 +console.log(myLocale.toString()); // "ja-u-ca-gregory-hc-h24" と表示 +let myLocMaximized = myLocale.maximize(); + +// "ja-Jpan-JP"。 "Jpan" と "JP" タグが追加されます。 +// これは、日本語が主に漢字かな交じり文 (Jpan) で書かれ、また主に日本 (JP) で話されているためです。 +console.log(myLocMaximized.baseName); + +// "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示します。 +// なお、拡張タグ ("-u" 以降) はそのまま残ります。 +console.log(myLocMaximized.toString()); </pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.maximize')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Locale.maximize")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li>{{jsxref("Locale/baseName", "Locale.baseName")}}</li> + <li><a href="https://www.unicode.org/reports/tr35/#Likely_Subtags">Unicode's Likely Subtags spec</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html new file mode 100644 index 0000000000..51c26a0498 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html @@ -0,0 +1,78 @@ +--- +title: Intl.Locale.prototype.minimize() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize +tags: + - Internationalization + - Intl + - JavaScript + - Method + - Prototype + - Reference + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.minimize()</code></strong> メソッドは、 {{jsxref("Locale/maximize", "Locale.maximize()")}} を呼び出したことで追加されるロケールに関する情報を削除しようとします。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-locale-prototype-minimize.html", "taller")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code><em>locale</em>.minimize()</code></pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>{{jsxref("Locale", "Locale")}} インスタンスで、 <code>baseName</code> プロパティが、 <a href="https://www.unicode.org/reports/tr35/#Likely_Subtags">Remove Likely Subtags</a> アルゴリズムが <code><em>locale.baseName</em></code> に対して実行された結果になったものを返します。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>このメソッドは {{jsxref("Locale/maximize", "maximize()")}} の逆の処理を行い、ロケールの言語識別子 (基本的には <code>baseName</code> の内容) から言語、文字体系、地域のサブタグをすべて削除します。これは、言語識別子の中に余分なサブタグがある場合に便利です。例えば "en-Latn" は "en" に簡略化できます。英語では "Latn" が書き言葉に使われる唯一の文字体系だからです。 <code>minimize()</code> が影響を与えるのは、<a href="https://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions">言語識別子</a>を構成する主要なサブタグである言語、文字体系、地域の各サブタグのみです。ロケール識別子の "-u" の後にあるその他のサブタグは拡張サブタグと呼ばれ、 <code>minimize()</code> メソッドの影響を受けません。これらのサブタグの例としては、 {{jsxref("Locale/hourCycle", "Locale.hourCycle")}}, {{jsxref("Locale/calendar", "Locale.calendar")}}, {{jsxref("Locale/numeric", "Locale.numeric")}} などがあります。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js">let myLocale = new Intl.Locale("ja-Jpan-JP", {hourCycle: "h24", calendar: "gregory"}); +console.log(myLocale.baseName); // "ja-Jpan-JP" と表示 +console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示 + +let myLocMinimized = myLocale.minimize(); + +// "ja" のみを表示します。日本語は主に漢字かな交じり文 (Jpan) で +// 表記され、またほとんど日本で話されているためです。 +console.log(myLocMinimized.baseName); + +// "ja-u-ca-gregory-hc-h24" と表示します。 +// なお、拡張タグ ("-u" 以降) はそのまま残ります。 +console.log(myLocMinimized.toString());</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.minimize')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Locale.minimize")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li>{{jsxref("Locale/baseName", "Intl.Locale.baseName")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.html new file mode 100644 index 0000000000..02d82c108e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.html @@ -0,0 +1,419 @@ +--- +title: Intl.Locale.prototype.numberingSystem +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.numberingSystem</code></strong> プロパティは、ロケールが使用する<a href="https://ja.wikipedia.org/wiki/%E5%91%BD%E6%95%B0%E6%B3%95">命数法</a>を返すアクセサープロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>命数法とは、数値を表現するための体系のことです。 <code>numberingSystem</code> プロパティは、世界中のさまざまな国、地域、文化で使用されているさまざまな命数法を表現する支援をします。ほとんどの国際化スキーマと同様に、 <code>Locale</code> オブジェクトで <code>numberingSystem</code> によって表現できる命数法は、 Unicode で標準化されています。標準的な Unicode の命数法の表を以下に示します。</p> + +<table class="standard-table"> + <tbody> + <tr> + <th>値</th> + <th>説明</th> + </tr> + <tr> + <td>adlm</td> + <td>Adlam digits</td> + </tr> + <tr> + <td>ahom</td> + <td>Ahom digits</td> + </tr> + <tr> + <td>arab</td> + <td>アラビア・インド数字</td> + </tr> + <tr> + <td>arabext</td> + <td>拡張アラビア・インド数字</td> + </tr> + <tr> + <td>armn</td> + <td>大文字のアルメニア数字 — アルゴリズム</td> + </tr> + <tr> + <td>armnlow</td> + <td>小文字のアルメニア数字 — アルゴリズム</td> + </tr> + <tr> + <td>bali</td> + <td>Balinese digits</td> + </tr> + <tr> + <td>beng</td> + <td>Bengali digits</td> + </tr> + <tr> + <td>bhks</td> + <td>Bhaiksuki digits</td> + </tr> + <tr> + <td>brah</td> + <td>Brahmi digits</td> + </tr> + <tr> + <td>cakm</td> + <td>Chakma digits</td> + </tr> + <tr> + <td>cham</td> + <td>Cham digits</td> + </tr> + <tr> + <td>cyrl</td> + <td>キリル数字 — アルゴリズム</td> + </tr> + <tr> + <td>deva</td> + <td>Devanagari digits</td> + </tr> + <tr> + <td>ethi</td> + <td>エチオピア数字 — アルゴリズム</td> + </tr> + <tr> + <td>finance</td> + <td>金融数字 — アルゴリズムの場合あり</td> + </tr> + <tr> + <td>fullwide</td> + <td>全角数字</td> + </tr> + <tr> + <td>geor</td> + <td>ジョージア数字 — アルゴリズム</td> + </tr> + <tr> + <td>gong</td> + <td>Gunjala Gondi digits</td> + </tr> + <tr> + <td>gonm</td> + <td>Masaram Gondi digits</td> + </tr> + <tr> + <td>grek</td> + <td>大文字のギリシャ数字 — アルゴリズム</td> + </tr> + <tr> + <td>greklow</td> + <td>小文字のギリシャ数字 — アルゴリズム</td> + </tr> + <tr> + <td>gujr</td> + <td>Gujarati digits</td> + </tr> + <tr> + <td>guru</td> + <td>Gurmukhi digits</td> + </tr> + <tr> + <td>hanidays</td> + <td>太陰暦またはその他の旧暦向けの漢字による日付の数字</td> + </tr> + <tr> + <td>hanidec</td> + <td>漢字を数字として使用した命数法</td> + </tr> + <tr> + <td>hans</td> + <td>簡体字の漢数字 — アルゴリズム</td> + </tr> + <tr> + <td>hansfin</td> + <td>簡体字の金融用漢数字 — アルゴリズム</td> + </tr> + <tr> + <td>hant</td> + <td>繁体字の漢数字 — アルゴリズム</td> + </tr> + <tr> + <td>hantfin</td> + <td>繁体字の金融用漢数字 — アルゴリズム</td> + </tr> + <tr> + <td>hebr</td> + <td>ヘブライ数字 — アルゴリズム</td> + </tr> + <tr> + <td>hmng</td> + <td>Pahawh Hmong digits</td> + </tr> + <tr> + <td>hmnp</td> + <td>Nyiakeng Puachue Hmong digits</td> + </tr> + <tr> + <td>java</td> + <td>Javanese digits</td> + </tr> + <tr> + <td>jpan</td> + <td>日本語の漢数字 — アルゴリズム</td> + </tr> + <tr> + <td>jpanfin</td> + <td>日本語の金融用漢数字 — アルゴリズム</td> + </tr> + <tr> + <td>jpanyear</td> + <td>日本語の元号用漢数字 (元年表記に対応)</td> + </tr> + <tr> + <td>kali</td> + <td>Kayah Li digits</td> + </tr> + <tr> + <td>khmr</td> + <td>Khmer digits</td> + </tr> + <tr> + <td>knda</td> + <td>Kannada digits</td> + </tr> + <tr> + <td>lana</td> + <td>Tai Tham Hora (secular) digits</td> + </tr> + <tr> + <td>lanatham</td> + <td>Tai Tham Tham (ecclesiastical) digits</td> + </tr> + <tr> + <td>laoo</td> + <td>Lao digits</td> + </tr> + <tr> + <td>latn</td> + <td>ラテン数字</td> + </tr> + <tr> + <td>lepc</td> + <td>Lepcha digits</td> + </tr> + <tr> + <td>limb</td> + <td>Limbu digits</td> + </tr> + <tr> + <td>mathbold</td> + <td>数学的太数字</td> + </tr> + <tr> + <td>mathdbl</td> + <td>数学的黒板太数字</td> + </tr> + <tr> + <td>mathmono</td> + <td>数学的等幅数字</td> + </tr> + <tr> + <td>mathsanb</td> + <td>数学的サンセリフ太数字</td> + </tr> + <tr> + <td>mathsans</td> + <td>数学的サンセリフ数字</td> + </tr> + <tr> + <td>mlym</td> + <td>Malayalam digits</td> + </tr> + <tr> + <td>modi</td> + <td>Modi digits</td> + </tr> + <tr> + <td>mong</td> + <td>Mongolian digits</td> + </tr> + <tr> + <td>mroo</td> + <td>Mro digits</td> + </tr> + <tr> + <td>mtei</td> + <td>Meetei Mayek digits</td> + </tr> + <tr> + <td>mymr</td> + <td>Myanmar digits</td> + </tr> + <tr> + <td>mymrshan</td> + <td>Myanmar Shan digits</td> + </tr> + <tr> + <td>mymrtlng</td> + <td>Myanmar Tai Laing digits</td> + </tr> + <tr> + <td>native</td> + <td>ネイティブの数字</td> + </tr> + <tr> + <td>newa</td> + <td>Newa digits</td> + </tr> + <tr> + <td>nkoo</td> + <td>N'Ko digits</td> + </tr> + <tr> + <td>olck</td> + <td>Ol Chiki digits</td> + </tr> + <tr> + <td>orya</td> + <td>Oriya digits</td> + </tr> + <tr> + <td>osma</td> + <td>Osmanya digits</td> + </tr> + <tr> + <td>rohg</td> + <td>Hanifi Rohingya digits</td> + </tr> + <tr> + <td>roman</td> + <td>大文字のローマ数字 — アルゴリズム</td> + </tr> + <tr> + <td>romanlow</td> + <td>小文字のローマ数字 — アルゴリズム</td> + </tr> + <tr> + <td>saur</td> + <td>Saurashtra digits</td> + </tr> + <tr> + <td>shrd</td> + <td>Sharada digits</td> + </tr> + <tr> + <td>sind</td> + <td>Khudawadi digits</td> + </tr> + <tr> + <td>sinh</td> + <td>Sinhala Lith digits</td> + </tr> + <tr> + <td>sora</td> + <td>Sora_Sompeng digits</td> + </tr> + <tr> + <td>sund</td> + <td>Sundanese digits</td> + </tr> + <tr> + <td>takr</td> + <td>Takri digits</td> + </tr> + <tr> + <td>talu</td> + <td>New Tai Lue digits</td> + </tr> + <tr> + <td>taml</td> + <td>タミル数字 — アルゴリズム</td> + </tr> + <tr> + <td>tamldec</td> + <td>Modern Tamil decimal digits</td> + </tr> + <tr> + <td>telu</td> + <td>Telugu digits</td> + </tr> + <tr> + <td>thai</td> + <td>Thai digits</td> + </tr> + <tr> + <td>tirh</td> + <td>Tirhuta digits</td> + </tr> + <tr> + <td>tibt</td> + <td>Tibetan digits</td> + </tr> + <tr> + <td>traditio</td> + <td>伝統的な数字 — アルゴリズムの場合あり</td> + </tr> + <tr> + <td>vaii</td> + <td>Vai digits</td> + </tr> + <tr> + <td>wara</td> + <td>Warang Citi digits</td> + </tr> + <tr> + <td>wcho</td> + <td>Wancho digits</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Setting_the_numberingSystem_value_via_the_locale_string" name="Setting_the_numberingSystem_value_via_the_locale_string">ロケール文字列から <code>numberingSystem</code> の値を設定</h3> + +<p><a href="https://www.unicode.org/reports/tr35/" rel="noopener">Unicode ロケール文字列仕様書</a>では、 <code>numberingSystem</code> が表す値はキー <code>nu</code> に対応しています。 <code>nu</code> はロケール文字列の「拡張サブタグ」とみなされます。これらのサブタグは、ロケールに関する追加データを追加するもので、拡張キー <code>-u</code> を使用してロケール識別子に追加されます。このようして、 <code>numberingSystem</code> の値を {{jsxref("Locale/Locale", "Locale")}} コンストラクターに渡される初期のロケール識別子文字列に追加することができます。 <code>numeric</code> の値を設定するには、まず文字列に <code>-u</code> 拡張キーを追加します。次に、 <code>-nu</code> 拡張キーを追加して、 <code>numberingSystem</code> の値を追加していることを示します。最後に、文字列に <code>numberingSystem</code> の値を追加します。</p> + +<pre class="brush: js">let numberingSystemViaStr = new Intl.Locale("fr-Latn-FR-u-nu-mong"); +console.log(numberingSystemStr.numberingSystem); // "mong" と表示</pre> + +<h3 id="Setting_the_numberingSystem_value_via_the_configuration_object_argument" name="Setting_the_numberingSystem_value_via_the_configuration_object_argument">構成オブジェクト引数から <code>numberingSystem</code> の値を設定</h3> + +<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、これを使用して拡張の種類を渡すことができます。構成オブジェクトの <code>numberingSystem</code> プロパティを任意の <code>numberingSystem</code> に設定し、コンストラクターに渡します。</p> + +<pre class="brush: js">let numberingSystemViaObj= new Intl.Locale("en-Latn-US", {numberingSystem: "latn"}); +console.log(us12hour.numberingSystem); // "latn" と表示 +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.numberingSystem')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.numberingSystem")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li><a href="https://github.com/unicode-org/cldr/blob/master/common/supplemental/numberingSystems.xml">標準 Unicode 数値体系の詳細</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/numeric/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/numeric/index.html new file mode 100644 index 0000000000..f60bc08e48 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/numeric/index.html @@ -0,0 +1,65 @@ +--- +title: Intl.Locale.prototype.numeric +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.numeric</code></strong> プロパティは、ロケールが特別な数字の照合処理を行うかどうかを返すアクセサプロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>{{jsxref("Locale.caseFirst", "Intl.Locale.caseFirst")}} と同様、 <code>numeric</code> はロケールが使用する照合規則を変更するものです。 <code>numeric</code> は {{jsxref("boolean", "Boolean")}} 値で、 <code>true</code> か <code>false</code> のどちらかになります。 <code>numeric</code> を <code>false</code> に設定した場合は、文字列内の数値を特別に扱うことはありません。 <code>numeric</code> を <code>true</code> に設定した場合は、ロケールは文字列を照合する際に数値を考慮します。この数値の特別な扱いとは、数字の並びを数値として比較するということです。例えば、 "A-21" という文字列は "A-123" よりも小さいとみなされます。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Setting_the_numeric_value_via_the_locale_string" name="Setting_the_numeric_value_via_the_locale_string">ロケール文字列から <code>numeric</code> の値を設定</h3> + +<p><a href="https://www.unicode.org/reports/tr35/" rel="noopener">Unicode ロケール文字列仕様書</a>では、 <code>numeric</code> が表す値はキー <code>kn</code> に対応しています。 <code>kn</code> はロケール文字列の「拡張サブタグ」とみなされます。これらのサブタグは、ロケールに関する追加データを追加するもので、拡張キー <code>-u</code> を使用してロケール識別子に追加されます。このようして、 <code>numeric</code> の値を {{jsxref("Locale/Locale", "Locale")}} コンストラクターに渡される初期のロケール識別子文字列に追加することができます。 <code>numeric</code> の値を設定するには、まず文字列に <code>-u</code> 拡張キーを追加します。次に、 <code>-kn</code> 拡張キーを追加して、 <code>numeric</code> の値を追加していることを示します。最後に、文字列に <code>numeric</code> の値を追加します。 <code>numeric</code> を <code>true</code> に設定したい場合は、単に <code>kn</code> キーを追加するだけで十分です。値を <code>false</code> にするには、 <code>kn</code> キーの後に "<code>false</code>" を指定する必要があります。</p> + +<pre class="brush: js">let numericViaStr = new Intl.Locale("fr-Latn-FR-u-kn-false"); +console.log(numericStr.numeric); // "false" と表示</pre> + +<h3 id="Setting_the_numeric_value_via_the_configuration_object_argument" name="Setting_the_numeric_value_via_the_configuration_object_argument">構成オブジェクト引数から <code>numeric</code> の値を設定</h3> + +<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、これを使用して拡張の種類を渡すことができます。構成オブジェクトの <code>numeric</code> プロパティを任意の <code>numeric</code> に設定し、コンストラクターに渡します。</p> + +<pre class="brush: js">let numericViaObj= new Intl.Locale("en-Latn-US", {numeric: true}); +console.log(us12hour.numeric); // "true" と表示 +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.numeric')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.numeric")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/region/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/region/index.html new file mode 100644 index 0000000000..d547e24b15 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/region/index.html @@ -0,0 +1,67 @@ +--- +title: Intl.Locale.prototype.region +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/region +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/region +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Locale.prototype.region</code></strong> プロパティは、ロケールに関連付けられた世界の地域 (ふつうは国) 返すアクセサープロパティです。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>地域は、ロケールを世界の特定の地域に位置づけるための、ロケール識別子の重要な要素となります。ロケールの地域を知ることは、ロケール間の違いを識別する上で非常に重要です。たとえば、イギリスとアメリカ合衆国では英語が使われていますが、両国間では綴りやその他の言語の慣習に違いがあります。ロケールの地域を知ることで、 JavaScript プログラマーがサイトやアプリケーションのコンテンツを世界の様々な地域から見たときに正しく表示されるようにするのに役立ちます。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Setting_the_region_in_the_locale_identifer_string_argument" name="Setting_the_region_in_the_locale_identifer_string_argument">ロケール識別子の文字列引数で地域を設定</h3> + +<p>地域は、有効な Unicode 言語識別子文字列の3番目の部分であり、これを {{jsxref("Locale/Locale", "Locale")}} コンストラクターに渡すロケール識別子文字列に追加することで設定することができます。なお、地域はロケール識別子の必須項目ではありません。</p> + +<pre class="brush: js">let regionStr = new Intl.Locale("en-Latn-US"); + +console.log(regionStr.region); // "US" と表示</pre> + +<h3 id="Setting_the_region_via_the_configuration_object" name="Setting_the_region_via_the_configuration_object">構成オブジェクトから地域を設定</h3> + +<p>{{jsxref("Locale/Locale", "Locale")}} コンストラクターは構成オブジェクトを取り、これを用いて地域のサブタグとプロパティを設定することができます。</p> + +<pre class="brush: js">let regionObj = new Intl.Locale("ja-Jpan", {region: "JP"}); + +console.log(scriptObj.script); // "JP" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.region')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.region")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li><a href="https://www.unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html">Unicode region chart</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/script/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/script/index.html new file mode 100644 index 0000000000..10452b6342 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/script/index.html @@ -0,0 +1,67 @@ +--- +title: Intl.Locale.prototype.script +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/script +tags: + - Internationalization + - Intl + - JavaScript + - Property + - Prototype + - Reference + - プロパティ + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/script +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.script</code></strong> プロパティは、ロケールで使われている特定の言語を書くための文字体系を返すアクセサープロパティです。</span></p> + +<h2 id="Description" name="Description">解説</h2> + +<p>文字体系は、用字系と呼ばれることもありますが、ロケールの核となる属性の一つです。これは、特定の言語を書くために使用される記号やグリフの集合を示しています。例えば、英語の文字はラテン文字ですが、韓国語の文字はハングルです。多くの場合、言語 (これは必須) は単一の文字体系でしか書かれないので、文字体系を記述することは厳密には必要ありません。この規則には例外があり、完全な Unicode 言語識別子を持つためには、可能な限りスクリプトを示すことが重要です。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Setting_the_script_in_the_locale_identifer_string_argument" name="Setting_the_script_in_the_locale_identifer_string_argument">ロケール識別子の文字列引数で文字体系を設定</h3> + +<p>文字体系は、有効な Unicode 言語識別子文字列の2番目の部分であり、これを {{jsxref("Locale/Locale", "Locale")}} コンストラクターに渡すロケール識別子文字列に追加することで設定することができます。なお、文字体系はロケール識別子の必須項目ではありません。</p> + +<pre class="brush: js">let scriptStr = new Intl.Locale("en-Latn-US"); + +console.log(scriptStr.script); // "Latn" と表示</pre> + +<h3 id="Setting_the_script_via_the_configuration_object" name="Setting_the_script_via_the_configuration_object">構成オブジェクトから文字体系を設定</h3> + +<p>{{jsxref("Locale/Locale", "Locale")}} コンストラクターは構成オブジェクトを取り、これを用いて文字体系のサブタグとプロパティを設定することができます。</p> + +<pre class="brush: js">let scriptObj = new Intl.Locale("ja-JP", {script: "Jpan"}); + +console.log(scriptObj.script); // "Jpan" と表示</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.script')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<div>{{Compat("javascript.builtins.Intl.Locale.script")}}</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li><a href="https://www.unicode.org/reports/tr35/#unicode_script_subtag_validity">Unicode's script subtag specification</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html new file mode 100644 index 0000000000..104a328f21 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html @@ -0,0 +1,67 @@ +--- +title: Intl.Locale.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString +tags: + - Intl + - JavaScript + - Method + - Prototype + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.toString()</code></strong> は、このロケールの完全な<a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">ロケール識別子文字列</a>を返します。</span></p> + +<div>{{EmbedInteractiveExample("pages/js/intl-locale-prototype-tostring.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code><em>locale</em>.toString()</code></pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>この<em>ロケール</em>の Unicode ロケール識別子文字列です。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>Locale</code> オブジェクトは、概念的な Unicode ロケール識別子を JavaScript で表現したものです。特定のロケールに関する情報 (言語、文字体系、カレンダーの種類など) を、ロケール識別子文字列で符号化することができます。これらのロケール識別子をより簡単に扱えるようにするために、 <code>Locale</code> オブジェクトが JavaScript に導入されました。 Locale オブジェクトの <code>toString</code> メソッドをコールすると、そのロケールの識別子文字列を返します。 <code>toString</code> メソッドを使用すると、 <code>Locale</code> のインスタンスが既存の <code>Intl</code> のコンストラクターへの引数ととして JSON におけるシリアライズにおいて、またはその他のコンテキストで正確な文字列表現が有用な場合に提供することができます。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js">let myLocale = new Intl.Locale("ja-Jpan-JP", {hourCycle: "h24", calendar: "gregory"}); +console.log(myLocale.baseName); // "ja-Jpan-JP" と表示 +console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示 +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.toString')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.Locale.toString")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Locale", "Intl.Locale")}}</li> + <li>{{jsxref("Locale/baseName", "Intl.Locale.baseName")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html new file mode 100644 index 0000000000..38e1b6926c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html @@ -0,0 +1,89 @@ +--- +title: Intl.NumberFormat.prototype.format() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format +tags: + - Internationalization + - Intl + - JavaScript + - Method + - NumberFormat + - Prototype + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat.prototype.format()</code></strong> メソッドは、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-numberformat-prototype-format.html", "taller")}}</div> + +<p class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code><var>numberFormat</var>.format(<var>number</var>)</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>number</code></dt> + <dd>整形する {{jsxref("Number")}} または {{jsxref("BigInt")}} です。</dd> +</dl> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>format</code> ゲッター関数は、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形し、文字列に格納します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_format" name="Using_format"><code>format</code> の使用</h3> + +<p><code>format</code> ゲッター関数を使用して単一の通貨値を整形しましょう。こちらはロシアの例です。</p> + +<pre class="brush: js">var options = { style: 'currency', currency: 'RUB' }; +var numberFormat = new Intl.NumberFormat('ru-RU', options); +console.log(numberFormat.format(654321.987)); +// → "654 321,99 руб." +</pre> + +<h3 id="Using_format_with_map" name="Using_format_with_map"><code>format</code> と <code>map</code> の使用</h3> + +<p><code>format</code> ゲッター関数を使用して、配列内のすべての数値を整形することができます。なお、この関数は供給元である {{jsxref("NumberFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map")}} に渡すことができます。</p> + +<pre class="brush: js">var a = [123456.789, 987654.321, 456789.123]; +var numberFormat = new Intl.NumberFormat('es-ES'); +var formatted = a.map(numberFormat.format); +console.log(formatted.join('; ')); +// → "123.456,789; 987.654,321; 456.789,123" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.numberformat.prototype.format', 'Intl.NumberFormat.prototype.format')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.format")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> + <li>{{jsxref("Number.prototype.toLocaleString()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html new file mode 100644 index 0000000000..5d4a91fc85 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html @@ -0,0 +1,151 @@ +--- +title: Intl.NumberFormat.prototype.formatToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts +tags: + - Internationalization + - Intl + - JavaScript + - Method + - NumberFormat + - Prototype + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Numberformat.prototype.formatToParts()</code></strong> メソッドは <code>NumberTimeFormat</code> フォーマッターによって生成された文字列のロケールに応じた書式設定を可能にします。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate">Intl.NumberFormat.prototype.formatToParts(number)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>number</code> {{optional_inline}}</dt> + <dd>書式化する {{jsxref("Number")}} または {{jsxref("BigInt")}}。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>書式化された数値を含む要素のオブジェクトの {{jsxref("Array")}}。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>formatToParts()</code> メソッドは、数値文字列のカスタム書式設定を行うときに便利です。ロケール固有のトークンを含むオブジェクトの {{jsxref("Array")}} を返します。その <code>formatToParts()</code> メソッドが返す構造体は、次のようになります。</p> + +<pre class="brush: js notranslate">[ + { type: "integer", value: "3" }, + { type: "group", value: "." }, + { type: "integer", value: "500" } +]</pre> + +<p>可能なタイプは以下のとおりです。</p> + +<dl> + <dt>currency</dt> + <dd>通貨の文字列です。 "$" や "€" のような記号または "Dollar", "Euro" の文字列です。これらの文字列は <code>currencyDisplay</code> の特定方法に依存します。</dd> + <dt>decimal</dt> + <dd>小数点区切り文字 (".")。</dd> + <dt>fraction</dt> + <dd>小数点以下の数値。</dd> + <dt>group</dt> + <dd>グループ区切り文字 (",")。</dd> + <dt>infinity</dt> + <dd>{{jsxref("Infinity")}} 文字列 ("∞")。</dd> + <dt>integer</dt> + <dd>整数。</dd> + <dt>literal</dt> + <dd>書式設定された数字のリテラル文字列または空白。</dd> + <dt>minusSign</dt> + <dd>マイナス記号の文字列 ("-")。</dd> + <dt>nan</dt> + <dd>{{jsxref("NaN")}} の文字列 ("NaN")。</dd> + <dt>plusSign</dt> + <dd>プラス記号の文字列 ("+")。</dd> +</dl> + +<dl> + <dt>percentSign</dt> + <dd>パーセント文字列 ("%")。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Comparing_format_and_formatToParts" name="Comparing_format_and_formatToParts">format と formatToParts の比較</h3> + +<p><code>NumberFormat</code> はローカライズされた、直接操作できない文字列を出力します。</p> + +<pre class="brush: js notranslate">var number = 3500; + +var formatter = new Intl.NumberFormat('de-DE', { + style: 'currency', + currency: 'EUR' +}); + +formatter.format(number); +// "3.500,00 €" +</pre> + +<p>しかし、多くのユーザーインターフェースでは、この文字列の書式形式をカスタマイズしたいと要望があります。 <code>formatToParts</code> メソッドは <code>NumberFormat</code> フォーマッターによって生成された文字列を要素ごとの文字列として提供することでロケールに応じた書式設定を可能にします。</p> + +<pre class="brush: js notranslate">formatter.formatToParts(number); + +// 返値: +[ + { type: "integer", value: "3" }, + { type: "group", value: "." }, + { type: "integer", value: "500" }, + { type: "decimal", value: "," }, + { type: "fraction", value: "00" }, + { type: "literal", value: " " }, + { type: "currency", value: "€" } +] +</pre> + +<p>これで情報は個別に利用可能となり、カスタマイズされた方法でフォーマットして連結することができます。例えば {{jsxref("Array.prototype.map()")}}, <a href="/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions">アロー関数</a>, <a href="/ja/docs/Web/JavaScript/Reference/Statements/switch">switch 文</a>, <a href="/ja/docs/Web/JavaScript/Reference/Template_literals">テンプレートリテラル</a>, {{jsxref("Array.prototype.reduce()")}} を使います。</p> + +<pre class="brush: js notranslate">var numberString = formatter.formatToParts(number).map(({type, value}) => { + switch (type) { + case 'currency': return `<strong>${value}</strong>`; + default : return value; + } +}).reduce((string, part) => string + part); +</pre> + +<p>上記は<code>formatToParts()</code>メソッドを使い、通貨を太字にします。</p> + +<pre class="brush: js notranslate">console.log(numberString); +// "3.500,00 <strong>€</strong>"</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.numberformat.prototype.formattoparts', 'Intl.NumberFormat.prototype.formatToParts')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.formatToParts")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> + <li>{{jsxref("NumberFormat.format", "Intl.NumberFormat.prototype.format")}}</li> + <li>日付の書式化: {{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/index.html new file mode 100644 index 0000000000..75f0c153e7 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/index.html @@ -0,0 +1,148 @@ +--- +title: Intl.NumberFormat +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat +tags: + - Class + - Internationalization + - Intl + - JavaScript + - NumberFormat + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat</code></strong> オブジェクトは、言語に依存した数値書式を可能にするオブジェクトのコンストラクターです。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-numberformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/NumberFormat/NumberFormat", "Intl.NumberFormat()")}}</dt> + <dd>新しい <code>NumberFormat</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("NumberFormat.supportedLocalesOf", "Intl.NumberFormat.supportedLocalesOf()")}}</dt> + <dd>提供されたロケールのうち、実行時の既定のロケールにフォールバックせずにサポートされるものを配列に納めて返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("NumberFormat.format", "Intl.NumberFormat.prototype.format")}}</dt> + <dd>ゲッター関数で、ローケルに応じて、この {{jsxref("NumberFormat")}} オブジェクトのオプションを持つ数値を書式化する関数を返します。</dd> + <dt>{{jsxref("NumberFormat.formatToParts", "Intl.NumberFormat.prototype.formatToParts()")}}</dt> + <dd>オブジェクトの {{jsxref("Array")}} を返し、これは専用のロケールを意識した書式で使用することができる部品内の数値文字列を表します。</dd> + <dt>{{jsxref("NumberFormat.resolvedOptions", "Intl.NumberFormat.prototype.resolvedOptions()")}}</dt> + <dd>ローケルを反映しているプロパティとオブジェクトの初期化中に計算された照合オプションをもった新しいオブジェクトを返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_usage" name="Basic_usage">基本的な使用</h3> + +<p>ローケルを指定しない基本的な使い方では、既定のローケルとオプションで書式化された文字列が返されます。</p> + +<pre class="brush: js notranslate">var number = 3500; + +console.log(new Intl.NumberFormat().format(number)); +// → '3,500' 英語(U.S.)ロケールの場合 +</pre> + +<h3 id="locales_の使用">locales の使用</h3> + +<p>この例では、地域による数値書式の違いをいくつか紹介します。アプリケーションのユーザーインターフェイスで使われた言語書式を得るには、言語 (およびフォールバック言語) を <code>locales</code> 引数により指定してください。</p> + +<pre class="brush: js notranslate">var number = 123456.789; + +// ドイツではカンマを小数、ピリオドを千単位の区切りに用います +console.log(new Intl.NumberFormat('de-DE').format(number)); +// → 123.456,789 + +// ほとんどのアラビア語圏ではアラビア数字を用います +console.log(new Intl.NumberFormat('ar-EG').format(number)); +// → ١٢٣٤٥٦٫٧٨٩ + +// インドでは thousands/lakh/crore 区切りが用いられます +console.log(new Intl.NumberFormat('en-IN').format(number)); +// → 1,23,456.789 + +// nu 拡張キーにより漢数字などの番号方式が使えます +console.log(new Intl.NumberFormat('zh-Hans-CN-u-nu-hanidec').format(number)); +// → 一二三,四五六.七八九 + +// バリ語のようにサポートされないかもしれない言語を用いる場合は +// フォールバック言語を含めます。次の例ではインドネシア語です。 +console.log(new Intl.NumberFormat(['ban', 'id']).format(number)); +// → 123.456,789 +</pre> + +<h3 id="Using_options" name="Using_options">options の使用</h3> + +<p><code>options</code>引数を使うと結果をカスタマイズできます。</p> + +<pre class="brush: js notranslate">var number = 123456.789; + +// 通貨フォーマットを用います +console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number)); +// → 123.456,79 € + +// 日本円には小数点以下がありません +console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number)); +// → ¥123,457 + +// 有効数字を3桁に狭めます +console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number)); +// → 1,23,000 +</pre> + +<h3 id="style_と_unit_の使用">style と unit の使用</h3> + +<pre class="brush: js notranslate">console.log(new Intl.NumberFormat("pt-PT", { + style: 'unit', + unit: "mile-per-hour" +}).format(50)); +// → 50 mi/h + +console.log((16).toLocaleString('en-GB', { + style: "unit", + unit: "liter", + unitDisplay: "long" +})); +// → 16 litres +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#numberformat-objects', 'Intl.NumberFormat')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.html new file mode 100644 index 0000000000..2a1932a00b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.html @@ -0,0 +1,257 @@ +--- +title: Intl.NumberFormat() コンストラクター +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat +tags: + - Constructor + - Intl + - JavaScript + - NumberFormat + - Reference + - コンストラクター +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat()</code></strong> コンストラクターは、言語に依存した数値の書式を有効にするオブジェクトを生成します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-numberformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate">new Intl.NumberFormat([<var>locales</var>[, <var>options</var>]]) +</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code> {{optional_inline}}</dt> + <dd> + <p>BCP 47 言語タグを持つ文字列、またはそのような文字列の配列。 <code><var>locales</var></code> 引数の一般的な形式と解釈については、 {{jsxref("Intl", "Intl のページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。次の Unicode 拡張キーが許可されています。</p> + + <dl> + <dt><code>nu</code></dt> + <dd>使用される数値システムです。指定可能な値には "<code>adlm</code>", "<code>ahom</code>", "<code>arab</code>", "<code>arabext</code>", "<code>bali</code>", "<code>beng</code>", "<code>bhks</code>", "<code>brah</code>", "<code>cakm</code>", "<code>cham</code>", "<code>deva</code>", "<code>diak</code>", "<code>fullwide</code>", "<code>gong</code>", "<code>gonm</code>", "<code>gujr</code>", "<code>guru</code>", "<code>hanidec</code>", "<code>hmng</code>", "<code>hmnp</code>", "<code>java</code>", "<code>kali</code>", "<code>khmr</code>", "<code>knda</code>", "<code>lana</code>", "<code>lanatham</code>", "<code>laoo</code>", "<code>latn</code>", "<code>lepc</code>", "<code>limb</code>", "<code>mathbold</code>", "<code>mathdbl</code>", "<code>mathmono</code>", "<code>mathsanb</code>", "<code>mathsans</code>", "<code>mlym</code>", "<code>modi</code>", "<code>mong</code>", "<code>mroo</code>", "<code>mtei</code>", "<code>mymr</code>", "<code>mymrshan</code>", "<code>mymrtlng</code>", "<code>newa</code>", "<code>nkoo</code>", "<code>olck</code>", "<code>orya</code>", "<code>osma</code>", "<code>rohg</code>", "<code>saur</code>", "<code>segment</code>", "<code>shrd</code>", "<code>sind</code>", "<code>sinh</code>", "<code>sora</code>", "<code>sund</code>", "<code>takr</code>", "<code>talu</code>", "<code>tamldec</code>", "<code>telu</code>", "<code>thai</code>", "<code>tibt</code>", "<code>tirh</code>", "<code>vaii</code>", "<code>wara</code>", "<code>wcho</code>" があります。</dd> + </dl> + </dd> + <dt><code><var>options</var></code> {{optional_inline}}</dt> + <dd> + <p>以下のプロパティのすべてまたは一部を持つオブジェクトです。</p> + + <dl> + <dt><code>compactDisplay</code></dt> + <dd><code>notation</code> が "<code>compact</code>" の場合のみ使用されます。 "<code>short</code>" (既定値) または "<code>long</code>" のどちらかを取ります。</dd> + <dt><code>currency</code></dt> + <dd>通貨の書式で使用するための通貨です。利用可能な値は ISO 4217 通貨コードであり、例えば米ドルは "<code>USD</code>"、ユーロは "<code>EUR</code>"、日本円には "<code>JPY</code>" です。 — <a href="http://www.currency-iso.org/en/home/tables/table-a1.html">Current currency & funds code list</a> を参照してください。既定値はありません。 <code>style</code> が "<code>currency</code>" である場合、 <code>currency</code> プロパティを提供する必要があります。</dd> + <dt><code>currencyDisplay</code></dt> + <dd>通貨の書式で通貨を表示する方法です。利用可能な値は次の通りです。 + <ul> + <li>"<code>symbol</code>" はローカライズされた通貨記号、例えば € などを使用します。これが既定値です。</li> + <li>"<code>narrowSymbol</code>" は短い形式の記号を使用します ("US$100" ではなく "$100")。</li> + <li>"<code>code</code>" は ISO 通貨コードを使用します。</li> + <li>"<code>name</code>" はローカライズされた通貨名、例えば "<code>dollar</code>" を使用します。</li> + </ul> + </dd> + <dt><code>currencySign</code></dt> + <dd>多くのロケールでは、会計の書式はマイナス記号を追加する代わりに数値を括弧で囲みます。この形式は <code>currencySign</code> オプションを "<code>accounting</code>" に設定すると有効になります。既定値は "<code>standard</code>" です。</dd> + <dt><code>localeMatcher</code></dt> + <dd>使用するロケール比較アルゴリズムです。使用可能な値は "<code>lookup</code>" および "<code>best fit</code>" です。既定値は "<code>best fit</code>" です。このオプションについての情報は、 {{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}} を参照してください。</dd> + <dt><code>notation</code></dt> + <dd>数値を表示するための書式です。既定値は "<code>standard</code>" です。 + <ul> + <li>"<code>standard</code>" 通常の数値の書式です。</li> + <li>"<code>scientific</code>" return the order-of-magnitude for formatted number.</li> + <li>"<code>engineering</code>" return the exponent of ten when divisible by three</li> + <li>"<code>compact</code>" string representing exponent, defaults is using the "short" form.</li> + </ul> + </dd> + <dt><code>numberingSystem</code></dt> + <dd>Numbering System. Possible values include: "<code>arab</code>", "<code>arabext</code>", " <code>bali</code>", "<code>beng</code>", "<code>deva</code>", "<code>fullwide</code>", " <code>gujr</code>", "<code>guru</code>", "<code>hanidec</code>", "<code>khmr</code>", " <code>knda</code>", "<code>laoo</code>", "<code>latn</code>", "<code>limb</code>", "<code>mlym</code>", " <code>mong</code>", "<code>mymr</code>", "<code>orya</code>", "<code>tamldec</code>", " <code>telu</code>", "<code>thai</code>", "<code>tibt</code>".</dd> + <dt><code>signDisplay</code></dt> + <dd>When to display the sign for the number; defaults to "<code>auto</code>" + <ul> + <li>"<code>auto</code>" sign display for negative numbers only</li> + <li>"<code>never</code>" never display sign</li> + <li>"<code>always</code>" always display sign</li> + <li>"<code>exceptZero</code>" sign display for positive and negative numbers, but not zero</li> + </ul> + </dd> + <dt><code>style</code></dt> + <dd>The formatting style to use , the default is "<code>decimal</code>". + <ul> + <li>"<code>decimal</code>" for plain number formatting.</li> + <li>"<code>currency</code>" for currency formatting.</li> + <li>"<code>percent</code>" for percent formatting</li> + <li>"<code>unit</code>" for unit formatting</li> + </ul> + </dd> + <dt><code>unit</code></dt> + <dd>The unit to use in <code>unit</code> formatting, Possible values are core unit identifiers, defined in <a href="http://unicode.org/reports/tr35/tr35-general.html#Unit_Elements" rel="nofollow">UTS #35, Part 2, Section 6</a>. A <a href="https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier" rel="nofollow">subset</a> of units from the <a href="https://github.com/unicode-org/cldr/blob/master/common/validity/unit.xml">full list</a> was selected for use in ECMAScript. Pairs of simple units can be concatenated with "<code>-per-</code>" to make a compound unit. There is no default value; if the <code>style</code> is "<code>unit</code>", the <code>unit</code> property must be provided.</dd> + <dt><code>unitDisplay</code></dt> + <dd>The unit formatting style to use in <code>unit</code> formatting, the defaults is "<code>short</code>". + <ul> + <li>"<code>long</code>" (e.g., <code>16 litres</code>)</li> + <li>"<code>short</code>" (e.g., <code>16 l</code>)</li> + <li>"<code>narrow</code>" (e.g., <code>16l</code>)</li> + </ul> + </dd> + <dt><code>useGrouping</code></dt> + <dd>Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Possible values are true and false; the default is true.</dd> + </dl> + </dd> + <dd> + <p>The following properties fall into two groups: <code>minimumIntegerDigits</code>, <code>minimumFractionDigits</code>, and <code>maximumFractionDigits</code> in one group, <code>minimumSignificantDigits</code> and <code>maximumSignificantDigits</code> in the other. If at least one property from the second group is defined, then the first group is ignored.</p> + + <dl> + <dt><code>minimumIntegerDigits</code></dt> + <dd>The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1.</dd> + <dt><code>minimumFractionDigits</code></dt> + <dd>The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the <a href="http://www.currency-iso.org/en/home/tables/table-a1.html">ISO 4217 currency code list</a> (2 if the list doesn't provide that information).</dd> + <dt><code>maximumFractionDigits</code></dt> + <dd>The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of <code>minimumFractionDigits</code> and 3; the default for currency formatting is the larger of <code>minimumFractionDigits</code> and the number of minor unit digits provided by the <a href="http://www.currency-iso.org/en/home/tables/table-a1.html">ISO 4217 currency code list</a> (2 if the list doesn't provide that information); the default for percent formatting is the larger of <code>minimumFractionDigits</code> and 0.</dd> + <dt><code>minimumSignificantDigits</code></dt> + <dd>The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.</dd> + <dt><code>maximumSignificantDigits</code></dt> + <dd>The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.</dd> + </dl> + </dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_usage">Basic usage</h3> + +<p>In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.</p> + +<pre class="brush: js notranslate">let amount = 3500; + +console.log(new Intl.NumberFormat().format(amount)); +// → '3,500' if in US English locale</pre> + +<h3 id="Decimal_and_percent_formatting">Decimal and percent formatting</h3> + +<pre class="brush: js notranslate">let amount = 3500; + +new Intl.NumberFormat('en-US', {style: 'decimal'}).format(amount); +// → '3,500' +new Intl.NumberFormat('en-US', {style: 'percent'}).format(amount); +// → '350,000%' +</pre> + +<h3 id="Unit_formatting">Unit formatting</h3> + +<p>If the <code>style</code> is <code>'unit'</code>, a <code>unit</code> property must be provided. Optionally, <code>unitDisplay</code> controls the unit formatting.</p> + +<pre class="brush: js notranslate">let amount = 3500; + +new Intl.NumberFormat('en-US', {style: 'unit', unit: 'liter'}).format(amount); +// → '3,500 L' + +new Intl.NumberFormat('en-US', {style: 'unit', unit: 'liter', unitDisplay: 'long'}).format(amount); +// → '3,500 liters' +</pre> + +<h3 id="Currency_formatting">Currency formatting</h3> + +<p>If the <code>style</code> is <code>'currency'</code>, a <code>currency</code> property must be provided. Optionally, <code>currencyDisplay</code> and <code>currencySign</code> control the unit formatting.</p> + +<pre class="brush: js notranslate">let amount = -3500; +new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(amount); +// → '-$3,500.00' + +new Intl.NumberFormat('bn', { + style: 'currency', + currency: 'USD', + currencyDisplay: 'name' +}).format(amount); +// → '-3,500.00 US dollars' + +new Intl.NumberFormat('bn', { + style: 'currency', + currency: 'USD', + currencySign: 'accounting' +}).format(amount); +// → '($3,500.00)' +</pre> + +<h3 id="Scientific_engineering_or_compact_notations">Scientific, engineering or compact notations</h3> + +<p>Scientific and compact notation are represented by the <code>notation</code> option and can be formatted like this:</p> + +<pre class="brush: js notranslate">new Intl.NumberFormat('en-US', { notation: "scientific" }).format(987654321); +// → 9.877E8 + +new Intl.NumberFormat('pt-PT', { notation: "scientific" }).format(987654321); +// → 9,877E8 + +new Intl.NumberFormat('en-GB', { notation: "engineering" }).format(987654321); +// → 987.654E6 + +new Intl.NumberFormat('de', { notation: "engineering" }).format(987654321); +// → 987,654E6 + +new Intl.NumberFormat('zh-CN', { notation: "compact" }).format(987654321); +// → 9.9亿 + +new Intl.NumberFormat('fr', { + notation: "compact", + compactDisplay: "long" +}).format(987654321); +// → 988 millions + +new Intl.NumberFormat('en-GB', { + notation: "compact", + compactDisplay: "short" +}).format(987654321); +// → 988M</pre> + +<h3 id="Displaying_signs">Displaying signs</h3> + +<p>Display a sign for positive and negative numbers, but not zero:</p> + +<pre class="brush: js notranslate">new Intl.NumberFormat("en-US", { + style: "percent", + signDisplay: "exceptZero" +}).format(0.55); +// → '+55%'</pre> + +<p>Note that when the currency sign is "accounting", parentheses might be used instead of a minus sign:</p> + +<pre class="brush: js notranslate">new Intl.NumberFormat('bn', { + style: 'currency', + currency: 'USD', + currencySign: 'accounting', + signDisplay: 'always' +}).format(-3500); + +// → '($3,500.00)'</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl-numberformat-constructor', 'Intl.NumberFormat constructor')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.NumberFormat")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.html new file mode 100644 index 0000000000..e32c959169 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.html @@ -0,0 +1,139 @@ +--- +title: Intl.NumberFormat.prototype.resolvedOptions() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions +tags: + - Internationalization + - JavaScript + - Method + - NumberFormat + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions +--- +<div>{{JSRef}}</div> + +<p>ローケルを反映しているプロパティとこの{{jsxref("Global_Objects/NumberFormat", "NumberFormat")}}オブジェクトの初期化中に計算された数値変換オプションをもった新しいオブジェクトを返します。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox"><code><var>numberFormat</var>.resolvedOptions()</code></pre> + +<h2 id="説明">説明</h2> + +<p>ローケルを反映しているプロパティとこの{{jsxref("Global_Objects/NumberFormat", "NumberFormat")}}オブジェクトの初期化中に計算された数値変換オプションをもった新しいオブジェクトを返します。オブジェクトは次のプロパティを持っています。:</p> + +<dl> + <dt><code>locale</code></dt> + <dd>実際に使われているローケルに対するBCP47言語タグ。Unicode表現値が入力BCP47言語タグでリクエストされたら、このローケルに対してリクエストされサポートされているキー/バリューペアは<code>locale</code>に含まれます。</dd> + <dt><code>numberingSystem</code></dt> + <dd>Unicode表現キー<code>"nu"</code>を使うかデフォルトとして設定される値。</dd> + <dt><code>style</code></dt> + <dt><code>useGrouping</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。</dd> + <dt><code>currency</code></dt> + <dt><code>currencyDisplay</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。<code>style</code>が<code>"currency"</code>の場合のみ、これらのプロパティは存在しています。</dd> +</dl> + +<p>次の2つのプロパティのグループのうちどちらかのみが含まれています。:</p> + +<dl> + <dt><code>minimumIntegerDigits</code></dt> + <dt><code>minimumFractionDigits</code></dt> + <dt><code>maximumFractionDigits</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。<code>minimumSignificantDigits</code>または<code>maximumSignificantDigits</code>が<code>options</code>引数で提供されなかった場合のみ、これらのプロパティは存在しています。</dd> + <dt><code>minimumSignificantDigits</code></dt> + <dt><code>maximumSignificantDigits</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。 これらのプロパティのうち少なくとも1つが<code>options</code>引数で提供された場合のみ、これらのプロパティは存在しています。</dd> +</dl> + +<h2 id="例">例</h2> + +<h3 id="resolvedOptions_メソッドを使う"><code>resolvedOptions</code> メソッドを使う</h3> + +<pre class="brush: js">var de = new Intl.NumberFormat('de-DE'); +var usedOptions = de.resolvedOptions(); + +usedOptions.locale; // "de-DE" +usedOptions.numberingSystem; // "latn" +usedOption.style; // "decimal" +usedOptions.minimumIntegerDigits; // 1 +usedOptions.minimumFractionDigits; // 0 +usedOptions.maximumFractionDigits; // 3 +usedOptions.useGrouping; // true +</pre> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-11.3.3', 'Intl.NumberFormat.prototype.resolvedOptions')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>機能</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>基本サポート</td> + <td>{{CompatChrome("24")}}</td> + <td>{{CompatGeckoDesktop("29")}}</td> + <td>{{CompatIE("11")}}</td> + <td>{{CompatOpera("15")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>機能</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>基本サポート</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome("26")}}</td> + <td>{{CompatNo}}<br> + {{bug("864843")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="関連情報">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.html new file mode 100644 index 0000000000..8108241d0b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.html @@ -0,0 +1,84 @@ +--- +title: Intl.NumberFormat.supportedLocalesOf() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/supportedLocalesOf +tags: + - Internationalization + - JavaScript + - Method + - NumberFormat +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/supportedLocalesOf +--- +<div>{{JSRef("Global_Objects", "NumberFormat", "Intl,Collator,DateTimeFormat")}}</div> + +<h2 id="概要">概要</h2> + +<p>ランタイムのデフォルトローケルに戻る必要なしで数値変換でサポートされる提供されたローケルを含んでいる配列を返します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code>Intl.NumberFormat.supportedLocalesOf(<var>locales</var>[, <var>options</var>])</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>locales</code></dt> + <dd>BCP47言語タグをもった文字列、そのような文字列の配列。<code>locales</code>引数の一般的な形式に対して、{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_identification_and_negotiation", 1)}}を確認して下さい。</dd> + <dt><code>options</code></dt> + <dd> + <p>任意。次のプロパティを持つオブジェクト:</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使用するローケルマッチングアルゴリズム。利用可能な値は<code>"lookup"</code> や <code>"best fit"</code>です。デフォルトは<code>"best fit"</code>です。このオプションについての情報のために、{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}}を確認して下さい。</dd> + </dl> + </dd> +</dl> + +<h2 id="説明">説明</h2> + +<p><code>locales</code>で提供された言語パックのサブセットをもった配列を返します。返される言語タグでは、ランタイムが使われているローケルマッチングアルゴリズムが考慮して数値変換でローケルをサポートしているので、デフォルトローケルに戻る必要はありません。</p> + +<h2 id="例">例</h2> + +<h3 id="例_supportedLocalesOfを使う">例: <code>supportedLocalesOf</code>を使う</h3> + +<p>数値フォーマットで、バリ語ではなく、インドネシア語とドイツ語をサポートしているランタイムを仮定すると、<code>supportedLocalesOf</code> はインドネシア語とドイツ語の言語タグを返します。<code>pinyin</code> は数値フォーマットには適切ではなくインドネシア語では使われていません。インドネシアの特定のドイツ語はサポートされそうにもありません。<code>"lookup"</code>アルゴリズムの指定に注意して下さい。<code>"best fit"</code> はインドネシア語はバリ語に対して、十分にふさわしいと決定するかもしれません。というのも、 ほとんどのバリの人はインドネシア語も理解するからです。それゆえバリ言語タグも同様に返します。</p> + +<pre class="brush: js">var locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +var options = { localeMatcher: 'lookup' }; +console.log(Intl.NumberFormat.supportedLocalesOf(locales, options).join(', ')); +// → "id-u-co-pinyin, de-ID" +</pre> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-11.2.2', 'Intl.NumberFormat.supportedLocalesOf')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> + +<div> +<div> + + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.supportedLocalesOf")}}</p> +</div> +</div> + +<h2 id="関連情報">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/pluralrules/index.html b/files/ja/web/javascript/reference/global_objects/intl/pluralrules/index.html new file mode 100644 index 0000000000..da798e66e2 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/pluralrules/index.html @@ -0,0 +1,86 @@ +--- +title: Intl.PluralRules +slug: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules +tags: + - Class + - Internationalization + - Intl + - JavaScript + - PluralRules +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.PluralRules</code></strong> オブジェクトは、複数形が影響する書式や言語ルールを使用できるようにします。</p> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("PluralRules.PluralRules()", "Intl.PluralRules.PluralRules()")}}</dt> + <dd>新しい <code>Intl.PluralRules</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("Intl/PluralRules/supportedLocalesOf", "Intl.PluralRules.supportedLocalesOf()")}}</dt> + <dd>指定したロケールのうち、ランタイムの既定のロケールにフォールバックすることなく対応されているものが入った配列を返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("Intl/PluralRules/resolvedOptions", "Intl.PluralRules.prototype.resolvedOptions()")}}</dt> + <dd>オブジェクトの初期化中に計算されたロケールとコレクションのオプションを反映したプロパティを持った新しいオブジェクトを返します。</dd> + <dt>{{jsxref("Intl/PluralRules/select", "Intl.PluralRules.prototype.select()")}}</dt> + <dd>ロケールを意識した書式化に使用する複数形を示す {{jsxref("String")}} を返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_locales" name="Using_locales">locales の使用</h3> + +<p>この例では、ローカライズされた複数形ルールのいくつかをお見せします。アプリケーションのユーザーインターフェイスで使う言語のフォーマットを取得するには、 <code>locales</code> 引数に言語 (および必要に応じてフォールバック言語) を指定してください。</p> + +<pre class="brush: js notranslate">// アラビア語は別な複数形の規則を持っています。 + +new Intl.PluralRules('ar-EG').select(0); +// → 'zero' +new Intl.PluralRules('ar-EG').select(1); +// → 'one' +new Intl.PluralRules('ar-EG').select(2); +// → 'two' +new Intl.PluralRules('ar-EG').select(6); +// → 'few' +new Intl.PluralRules('ar-EG').select(18); +// → 'many' +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#pluralrules-objects', 'Intl.PluralRules')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.PluralRules")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/pluralrules/select/index.html b/files/ja/web/javascript/reference/global_objects/intl/pluralrules/select/index.html new file mode 100644 index 0000000000..af854453f6 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/pluralrules/select/index.html @@ -0,0 +1,84 @@ +--- +title: Intl.PluralRules.select() +slug: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/select +tags: + - Internationalization + - Intl + - JavaScript + - Method + - PluralRules + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/select +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.PluralRules.prototype.select</code></strong> メソッドは、ロケールを考慮した書式設定に使用する複数形ルールを示す String を返します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><code><var>pluralCategory = pluralRule</var>.select(<var>number</var>)</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>number</code></dt> + <dd>複数のルールを取得するための数値です。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>数字の複数形のカテゴリを表す <code>string</code> で、 <code>zero</code>, <code>one</code>, <code>two</code>, <code>few</code>, <code>many</code>, <code>other</code> のいずれかになります。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p>この関数は、 {{jsxref("PluralRules")}} オブジェクトのロケールや書式オプションに応じて、複数形のカテゴリを選択します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_select" name="Using_select">select() の使用</h3> + +<pre class="brush: js notranslate"> new Intl.PluralRules('ar-EG').select(0); +// → 'zero' + +new Intl.PluralRules('ar-EG').select(1); +// → 'one' + +new Intl.PluralRules('ar-EG').select(2); +// → 'two' + +new Intl.PluralRules('ar-EG').select(6); +// → 'few' + +new Intl.PluralRules('ar-EG').select(18); +// → 'many' +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.pluralrules.prototype.select', 'Intl.PluralRules.select()')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.PluralRules.select")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("PluralRules", "Intl.PluralRules")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.html b/files/ja/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.html new file mode 100644 index 0000000000..ea219a5f0c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.html @@ -0,0 +1,83 @@ +--- +title: Intl.PluralRules.supportedLocalesOf() +slug: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +tags: + - Internationalization + - Intl + - JavaScript + - Method + - PluralRules + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.PluralRules.supportedLocalesOf()</code></strong> メソッドは、ランタイムの既定のロケールで代替する必要なく複数形の書式で対応されているものを含む配列を返します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox">Intl.PluralRules.supportedLocalesOf(<var>locales</var>[, <var>options</var>])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code></dt> + <dd>BCP 47 言語タグを持つ文字列、またはそのような文字列の配列です。 <code>locales</code> 引数の一般的な形式については、 {{jsxref("Intl", "Intl のページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。</dd> + <dt><code><var>options</var></code></dt> + <dd> + <p>省略可能です。以下のプロパティを持つことがあるオブジェクトです。</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使用するロケールの一致アルゴリズムです。指定可能な値は <code>lookup</code> および <code>best fit</code> で、既定値は <code>best fit</code> です。このオプションの詳細は、 {{jsxref("Intl", "Intl のページ", "#Locale_negotiation", 1)}}を参照してください。</dd> + </dl> + </dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>指定したロケールタグのサブセットを表す文字列の配列で、ランタイムの既定のロケールで代替する必要なく複数形の書式で対応されているものを含みます。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>locales</code> で提供されている言語タグのサブセットを含む配列を返します。返される言語タグは、ランタイムが複数形のロケールに対応しているもので、使用しているロケール一致アルゴリズムで一致しているとみなされているものです。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_supportedLocalesOf" name="Using_supportedLocalesOf">supportedLocalesOf() の使用</h3> + +<p>複数形の書式でインドネシア語とドイツ語に対応しており、バリ語に対応していないランタイムを想定すると、 <code>supportedLocalesOf</code> はインドネシア語とドイツ語の言語タグを変更せずに返しますが、 <code>pinyin</code> の照合は複数形の書式には関係なく、インドネシア語でも使用されません。ここでの <code>lookup</code> アルゴリズムの仕様に注意してください — バリ語話者のほとんどはインドネシア語も理解しているので、 <code>best fit</code> のマッチャーはインドネシア語がバリ語に適切に一致すると判断し、バリ語の言語タグも返すかもしれません。</p> + +<pre class="brush: js">var locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +var options = { localeMatcher: 'lookup' }; +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); +// → "id-u-co-pinyin, de-ID" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様書</th> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.pluralrules.supportedlocalesof', 'Intl.PluralRules.supportedLocalesOf')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.PluralRules.supportedLocalesOf")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("PluralRules", "Intl.PluralRules")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.html b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.html new file mode 100644 index 0000000000..8529542ad8 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.html @@ -0,0 +1,109 @@ +--- +title: Intl.RelativeTimeFormat.prototype.format() +slug: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format +tags: + - IntI + - Internationalization + - JavaScript + - Method + - Reference + - RelativeTimeFormat +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.RelativeTimeFormat.prototype.format()</code></strong> メソッドは <code>value</code> や <code>unit</code> を、この {{jsxref("Intl.RelativeTimeFormat")}} オブジェクトのロケールと整形オプションに従って整形します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-relativetimeformat-prototype-format.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="brush: js notranslate"><var>relativeTimeFormat</var>.format(<var>value</var>, <var>unit</var>)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>value</var></code></dt> + <dd>国際化された相対時間のメッセージに使用する数値です。</dd> +</dl> + +<dl> + <dt><code><var>unit</var></code></dt> + <dd>国際化された相対時間のメッセージに使用する単位です。利用可能な値は、 "<code>year</code>", "<code>quarter</code>", "<code>month</code>", "<code>week</code>", "<code>day</code>", "<code>hour</code>", "<code>minute</code>", "<code>second</code>" です。複数形も許容されています。</dd> +</dl> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>format</code> ゲッター関数は、この {{jsxref("RelativeTimeFormat", "Intl.RelativeTimeFormat")}} オブジェクトのロケールと整形オプションに従って値や単位を整形し、文字列に格納します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_format_usage" name="Basic_format_usage">基本的な format の使い方</h3> + +<p>以下の例は、英語を使用した相対時間のフォーマッターの生成方法を示しています。</p> + +<pre class="brush: js notranslate">// ロケールで既定値を明確に指定して +// 相対時間フォーマッターを作成 +const rtf = new Intl.RelativeTimeFormat("en", { + localeMatcher: "best fit", // other values: "lookup" + numeric: "always", // other values: "auto" + style: "long", // other values: "short" or "narrow" +}); + +// 負の値 (-1) を使った相対時間の書式化 +rtf.format(-1, "day"); +// > "1 day ago" + +// 正の値 (1) を使った相対時間の書式化 +rtf.format(1, "day"); +// > "in 1 day"</pre> + +<h3 id="Using_the_auto_option" name="Using_the_auto_option">auto オプションの使用</h3> + +<p><code>numeric:auto</code> オプションが渡された場合は、 <code>1 day ago</code> や <code>in 1 day</code> の代わりに <code>yesterday</code> や <code>tomorrow</code> の文字列が生成されます。これにより、出力に数値が含まれなくなることがあります。</p> + +<pre class="brush: js notranslate">// ロケールで既定値を明確に指定して +// 相対時間フォーマッターを作成 +const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" }); + +// 負の値 (-1) を使った相対時間の書式化 +rtf.format(-1, "day"); +// > "yesterday" + +// 正の値 (1) を使った相対時間の書式化 +rtf.format(1, "day"); +// > "tomorrow" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.RelativeTimeFormat.prototype.format', 'RelativeTimeFormat.format()')}}</td> + <td>第 4 段階</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.RelativeTimeFormat.format")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl.RelativeTimeFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.html new file mode 100644 index 0000000000..01aea3d1f9 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.html @@ -0,0 +1,91 @@ +--- +title: Intl.RelativeTimeFormat.prototype.formatToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts +tags: + - Internationalization + - Intl + - JavaScript + - Method + - Prototype + - RelativeTimeFormat +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.RelativeTimeFormat.prototype.formatToParts()</code></strong> メソッドは、ロケールを考慮したカスタム書式設定に使用できる相対時間書式を部品単位で表すオブジェクトの配列 ({{jsxref("Array")}}) を返します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-relativetimeformat-prototype-formattoparts.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="brush: js notranslate">RelativeTimeFormat.formatToParts(<var>value</var>, <var>unit</var>)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>value</var></code></dt> + <dd>国際化された相対時間のメッセージに使用する数値です。</dd> +</dl> + +<dl> + <dt><code><var>unit</var></code></dt> + <dd>国際化された相対時間のメッセージに使用する単位です。利用可能な値は、 "<code>year</code>", "<code>quarter</code>", "<code>month</code>", "<code>week</code>", "<code>day</code>", "<code>hour</code>", "<code>minute</code>", "<code>second</code>" です。複数形も許容されています。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>書式化された相対時間を部品単位で含むオブジェクトの配列 ({{jsxref("Array")}}) です。</p> + +<h2 id="Description" name="Description">解説</h2> + +<div><code>Intl.RelativeTimeFormat.prototype.formatToParts</code> メソッドは、書式化メソッドのバージョンの一つで、書式化された数値を他の周囲のテキストから分離し、それぞれの構成部品に分解した、オブジェクトの「部分」を表すオブジェクトの配列を返すものです。これらのオブジェクトには二つのプロパティがあります。 type は <code>NumberFormat</code> の formatToParts 型で、値は出力の構成要素である文字列です。もし "part" が <code>NumberFormat</code> から来たものであれば、書式化された単位を示す unit プロパティを持ちます。</div> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_formatToParts" name="Using_formatToParts">formatToParts の使用</h3> + +<pre class="brush: js notranslate">const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" }); + +// Format relative time using the day unit +rtf.formatToParts(-1, "day"); +// > [{ type: "literal", value: "yesterday"}] + +rtf.formatToParts(100, "day"); +// > [{ type: "literal", value: "in " }, +// > { type: "integer", value: "100", unit: "day" }, +// > { type: "literal", value: " days" }]</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-Intl.RelativeTimeFormat.prototype.formatToParts', 'RelativeTimeFormat.formatToParts()')}}</td> + <td>第 4 段階</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.RelativeTimeFormat.format")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl.RelativeTimeFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/index.html new file mode 100644 index 0000000000..1e774a8b10 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/index.html @@ -0,0 +1,112 @@ +--- +title: Intl.RelativeTimeFormat +slug: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +tags: + - Class + - Internationalization + - Intl + - JavaScript + - RelativeTimeFormat +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.RelativeTimeFormat</code></strong> オブジェクトは言語に依存の相対時間の書式化を可能にします。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-relativetimeformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力していただける場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/RelativeTimeFormat/RelativeTimeFormat", "Intl.RelativeTimeFormat.RelativeTimeFormat()")}}</dt> + <dd>新しい <code>Intl.RelativeTimeFormat</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("Intl/RelativeTimeFormat/supportedLocalesOf", "Intl.RelativeTimeFormat.supportedLocalesOf()")}}</dt> + <dd>指定されたロケールのうち、実行時の既定のロケールにフォールバックせずに対応されるものを配列に収めて返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("Intl/RelativeTimeFormat/format", "Intl.RelativeTimeFormat.prototype.format()")}}</dt> + <dd><code>value</code> および <code>unit</code> を、指定された {{jsxref("Intl.RelativeTimeFormat")}} オブジェクトのロケールと書式化オプションに従って書式化します。</dd> + <dt>{{jsxref("Intl/RelativeTimeFormat/formatToParts", "Intl.RelativeTimeFormat.prototype.formatToParts()")}}</dt> + <dd>ロケール固有のカスタムフォーマットに使用可能な相対時間のフォーマットを部分的に表現したオブジェクトの {{jsxref("Array")}} を返します。</dd> + <dt>{{jsxref("Intl/RelativeTimeFormat/resolvedOptions", "Intl.RelativeTimeFormat.prototype.resolvedOptions()")}}</dt> + <dd>オブジェクトの初期化中に計算されたロケールやフォーマットのオプションを反映したプロパティを持つ新しいオブジェクトを返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_format_usage" name="Basic_format_usage">基本的な <code>format</code> の使用例</h3> + +<p>以下は英語の相対時間フォーマッターの使い方の例です。</p> + +<pre class="brush: js notranslate">// 明示的に渡された既定値を使って +// ロケールの相対時間を生成します +const rtf = new Intl.RelativeTimeFormat("en", { + localeMatcher: "best fit", // other values: "lookup" + numeric: "always", // other values: "auto" + style: "long", // other values: "short" or "narrow" +}); + +// 負数の値 (-1) を使った相対時間のフォーマット +rtf.format(-1, "day"); +// > "1 day ago" + +// 正数の値 (1) を使った相対時間のフォーマット +rtf.format(1, "day"); +// > "in 1 day"</pre> + +<h3 id="Using_formatToParts" name="Using_formatToParts">formatToParts の使用例</h3> + +<p>以下はフォーマットされた部品を返す相対時間フォーマッターの生成方法の例です。</p> + +<pre class="brush: js notranslate">const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" }); + +// 日単位の相対時間フォーマット +rtf.formatToParts(-1, "day"); +// > [{ type: "literal", value: "yesterday"}] + +rtf.formatToParts(100, "day"); +// > [{ type: "literal", value: "in " }, +// > { type: "integer", value: "100", unit: "day" }, +// > { type: "literal", value: " days" }] +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#relativetimeformat-objects', 'RelativeTimeFormat')}}</td> + <td>第 4 段階</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.RelativeTimeFormat")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="https://developers.google.com/web/updates/2018/10/intl-relativetimeformat">The Intl.RelativeTimeFormat API</a></li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.html new file mode 100644 index 0000000000..fdc22fa753 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.html @@ -0,0 +1,122 @@ +--- +title: Intl.RelativeTimeFormat() コンストラクター +slug: >- + Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat +tags: + - Constructor + - Internationalization + - Intl + - JavaScript + - Reference + - RelativeTimeFormat +translation_of: >- + Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.RelativeTimeFormat()</code></strong> コンストラクターは、 {{jsxref("Intl/RelativeTimeFormat", "Intl.RelativeTimeFormat")}} オブジェクトを生成します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="notranslate">new Intl.RelativeTimeFormat([<var>locales</var>[, <var>options</var>]])</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code> {{optional_inline}}</dt> + <dd> + <p>BCP 47 言語タグを持つ文字列か、そのような文字列の配列です。 <code>locales</code> 引数の一般的な形式と解釈については、 {{jsxref("Global_Objects/Intl", "Intl ページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。</p> + </dd> + <dt><code><var>options</var></code> {{optional_inline}}</dt> + <dd>以下のプロパティのうち一部またはすべてを持つオブジェクトです。 + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使用するロケールの一致アルゴリズムです。指定可能な値は <code>lookup</code> および <code>best fit</code> で、既定値は <code>best fit</code> です。このオプションの詳細は、 {{jsxref("Global_Objects/IntlIntl", "Intl", "#Locale_negotiation")}} を参照してください。</dd> + <dt><code>numeric</code></dt> + <dd>メッセージを出力する書式です。利用可能な値は次の通りです。 + <ul> + <li>"<code>always</code>" (既定値、例えば <code>1 日前</code>)</li> + <li>"<code>auto</code>" (例えば <code>昨日</code>)。 "<code>auto</code>" にすると、出力に常に数値が入るとは限りません。</li> + </ul> + </dd> + <dt><code>style</code></dt> + <dd>国際化されたメッセージの長さです。利用可能な値は次の通りです。 + <ul> + <li>"<code>long</code>" (既定値、例えば <code>in 1 month</code>)</li> + <li>"<code>short</code>" (例えば <code>in 1 mo.</code>)</li> + <li>"<code>narrow</code>" (例えば <code>in 1 mo.</code>) narrow スタイルは同じロケールでは short スタイルと同様になることがあります。</li> + </ul> + </dd> + </dl> + </dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_format_usage" name="Basic_format_usage">基本的な書式の使い方</h3> + +<p>以下の例は、英語を使用した相対時間のフォーマッターの生成方法を示しています。</p> + +<pre class="brush: js notranslate">// Create a relative time formatter in your locale +// with default values explicitly passed in. +const rtf = new Intl.RelativeTimeFormat("en", { + localeMatcher: "best fit", // other values: "lookup" + numeric: "always", // other values: "auto" + style: "long", // other values: "short" or "narrow" +}); + +// 負の値 (-1) を使った相対時間のフォーマット +rtf.format(-1, "day"); +// > "1 day ago" + +// 正の値 (1) を使った相対時間のフォーマット +rtf.format(1, "day"); +// > "in 1 day"</pre> + +<h3 id="Using_the_auto_option" name="Using_the_auto_option">auto オプションの使用</h3> + +<p><code>numeric:auto</code> オプションが渡された場合は、 <code>1 day ago</code> や <code>in 1 day</code> の代わりに <code>yesterday</code> や <code>tomorrow</code> の文字列が生成されます。これにより、出力に数値が含まれなくなることがあります。</p> + +<pre class="brush: js notranslate">// Create a relative time formatter in your locale +// with numeric: "auto" option value passed in. +const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" }); + +// Format relative time using negative value (-1). +rtf.format(-1, "day"); +// > "yesterday" + +// Format relative time using positive day unit (1). +rtf.format(1, "day"); +// > "tomorrow" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl-relativetimeformat-constructor', 'RelativeTimeFormat()')}}</td> + <td>第 4 段階</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.RelativeTimeFormat.RelativeTimeFormat")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="https://developers.google.com/web/updates/2018/10/intl-relativetimeformat">The Intl.RelativeTimeFormat API</a></li> +</ul> |
