From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../intl/relativetimeformat/format/index.html | 109 ++++++++++++++++++ .../relativetimeformat/formattoparts/index.html | 91 +++++++++++++++ .../intl/relativetimeformat/index.html | 112 +++++++++++++++++++ .../relativetimeformat/index.html | 122 +++++++++++++++++++++ 4 files changed, 434 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.html (limited to 'files/ja/web/javascript/reference/global_objects/intl/relativetimeformat') 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 +--- +
{{JSRef}}
+ +

Intl.RelativeTimeFormat.prototype.format() メソッドは valueunit を、この {{jsxref("Intl.RelativeTimeFormat")}} オブジェクトのロケールと整形オプションに従って整形します。

+ +
{{EmbedInteractiveExample("pages/js/intl-relativetimeformat-prototype-format.html")}}
+ + + +

構文

+ +
relativeTimeFormat.format(value, unit)
+ +

引数

+ +
+
value
+
国際化された相対時間のメッセージに使用する数値です。
+
+ +
+
unit
+
国際化された相対時間のメッセージに使用する単位です。利用可能な値は、 "year", "quarter", "month", "week", "day", "hour", "minute", "second" です。複数形も許容されています。
+
+ +

解説

+ +

format ゲッター関数は、この {{jsxref("RelativeTimeFormat", "Intl.RelativeTimeFormat")}} オブジェクトのロケールと整形オプションに従って値や単位を整形し、文字列に格納します。

+ +

+ +

基本的な format の使い方

+ +

以下の例は、英語を使用した相対時間のフォーマッターの生成方法を示しています。

+ +
// ロケールで既定値を明確に指定して
+// 相対時間フォーマッターを作成
+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"
+ +

auto オプションの使用

+ +

numeric:auto オプションが渡された場合は、 1 day agoin 1 day の代わりに yesterdaytomorrow の文字列が生成されます。これにより、出力に数値が含まれなくなることがあります。

+ +
// ロケールで既定値を明確に指定して
+// 相対時間フォーマッターを作成
+const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
+
+// 負の値 (-1) を使った相対時間の書式化
+rtf.format(-1, "day");
+// > "yesterday"
+
+// 正の値 (1) を使った相対時間の書式化
+rtf.format(1, "day");
+// > "tomorrow"
+
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('ES Int Draft', '#sec-Intl.RelativeTimeFormat.prototype.format', 'RelativeTimeFormat.format()')}}第 4 段階
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Intl.RelativeTimeFormat.format")}}

+ +

関連情報

+ + 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 +--- +
{{JSRef}}
+ +

Intl.RelativeTimeFormat.prototype.formatToParts() メソッドは、ロケールを考慮したカスタム書式設定に使用できる相対時間書式を部品単位で表すオブジェクトの配列 ({{jsxref("Array")}}) を返します。

+ +
{{EmbedInteractiveExample("pages/js/intl-relativetimeformat-prototype-formattoparts.html")}}
+ + + +

構文

+ +
RelativeTimeFormat.formatToParts(value, unit)
+ +

引数

+ +
+
value
+
国際化された相対時間のメッセージに使用する数値です。
+
+ +
+
unit
+
国際化された相対時間のメッセージに使用する単位です。利用可能な値は、 "year", "quarter", "month", "week", "day", "hour", "minute", "second" です。複数形も許容されています。
+
+ +

返値

+ +

書式化された相対時間を部品単位で含むオブジェクトの配列 ({{jsxref("Array")}}) です。

+ +

解説

+ +
Intl.RelativeTimeFormat.prototype.formatToParts メソッドは、書式化メソッドのバージョンの一つで、書式化された数値を他の周囲のテキストから分離し、それぞれの構成部品に分解した、オブジェクトの「部分」を表すオブジェクトの配列を返すものです。これらのオブジェクトには二つのプロパティがあります。 type は NumberFormat の formatToParts 型で、値は出力の構成要素である文字列です。もし "part" が NumberFormat から来たものであれば、書式化された単位を示す unit プロパティを持ちます。
+ +

+ +

formatToParts の使用

+ +
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" }]
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('ES Int Draft', '#sec-Intl.RelativeTimeFormat.prototype.formatToParts', 'RelativeTimeFormat.formatToParts()')}}第 4 段階
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("javascript.builtins.Intl.RelativeTimeFormat.format")}}

+
+ +

関連情報

+ + 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 +--- +
{{JSRef}}
+ +

Intl.RelativeTimeFormat オブジェクトは言語に依存の相対時間の書式化を可能にします。

+ +
{{EmbedInteractiveExample("pages/js/intl-relativetimeformat.html")}}
+ + + +

コンストラクター

+ +
+
{{jsxref("Intl/RelativeTimeFormat/RelativeTimeFormat", "Intl.RelativeTimeFormat.RelativeTimeFormat()")}}
+
新しい Intl.RelativeTimeFormat オブジェクトを生成します。
+
+ +

静的メソッド

+ +
+
{{jsxref("Intl/RelativeTimeFormat/supportedLocalesOf", "Intl.RelativeTimeFormat.supportedLocalesOf()")}}
+
指定されたロケールのうち、実行時の既定のロケールにフォールバックせずに対応されるものを配列に収めて返します。
+
+ +

インスタンスメソッド

+ +
+
{{jsxref("Intl/RelativeTimeFormat/format", "Intl.RelativeTimeFormat.prototype.format()")}}
+
value および unit を、指定された {{jsxref("Intl.RelativeTimeFormat")}} オブジェクトのロケールと書式化オプションに従って書式化します。
+
{{jsxref("Intl/RelativeTimeFormat/formatToParts", "Intl.RelativeTimeFormat.prototype.formatToParts()")}}
+
ロケール固有のカスタムフォーマットに使用可能な相対時間のフォーマットを部分的に表現したオブジェクトの {{jsxref("Array")}} を返します。
+
{{jsxref("Intl/RelativeTimeFormat/resolvedOptions", "Intl.RelativeTimeFormat.prototype.resolvedOptions()")}}
+
オブジェクトの初期化中に計算されたロケールやフォーマットのオプションを反映したプロパティを持つ新しいオブジェクトを返します。
+
+ +

+ +

基本的な format の使用例

+ +

以下は英語の相対時間フォーマッターの使い方の例です。

+ +
// 明示的に渡された既定値を使って
+// ロケールの相対時間を生成します
+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"
+ +

formatToParts の使用例

+ +

以下はフォーマットされた部品を返す相対時間フォーマッターの生成方法の例です。

+ +
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" }]
+
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('ES Int Draft', '#relativetimeformat-objects', 'RelativeTimeFormat')}}第 4 段階
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Intl.RelativeTimeFormat")}}

+ +

関連情報

+ + 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 +--- +
{{JSRef}}
+ +

Intl.RelativeTimeFormat() コンストラクターは、 {{jsxref("Intl/RelativeTimeFormat", "Intl.RelativeTimeFormat")}} オブジェクトを生成します。

+ +

構文

+ +
new Intl.RelativeTimeFormat([locales[, options]])
+ +

引数

+ +
+
locales {{optional_inline}}
+
+

BCP 47 言語タグを持つ文字列か、そのような文字列の配列です。 locales 引数の一般的な形式と解釈については、 {{jsxref("Global_Objects/Intl", "Intl ページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。

+
+
options {{optional_inline}}
+
以下のプロパティのうち一部またはすべてを持つオブジェクトです。 +
+
localeMatcher
+
使用するロケールの一致アルゴリズムです。指定可能な値は lookup および best fit で、既定値は best fit です。このオプションの詳細は、 {{jsxref("Global_Objects/IntlIntl", "Intl", "#Locale_negotiation")}} を参照してください。
+
numeric
+
メッセージを出力する書式です。利用可能な値は次の通りです。 +
    +
  • "always" (既定値、例えば 1 日前)
  • +
  • "auto" (例えば 昨日)。 "auto" にすると、出力に常に数値が入るとは限りません。
  • +
+
+
style
+
国際化されたメッセージの長さです。利用可能な値は次の通りです。 +
    +
  • "long" (既定値、例えば in 1 month)
  • +
  • "short" (例えば in 1 mo.)
  • +
  • "narrow" (例えば in 1 mo.) narrow スタイルは同じロケールでは short スタイルと同様になることがあります。
  • +
+
+
+
+
+ +

+ +

基本的な書式の使い方

+ +

以下の例は、英語を使用した相対時間のフォーマッターの生成方法を示しています。

+ +
// 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"
+ +

auto オプションの使用

+ +

numeric:auto オプションが渡された場合は、 1 day agoin 1 day の代わりに yesterdaytomorrow の文字列が生成されます。これにより、出力に数値が含まれなくなることがあります。

+ +
// 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"
+
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('ES Int Draft', '#sec-intl-relativetimeformat-constructor', 'RelativeTimeFormat()')}}第 4 段階
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Intl.RelativeTimeFormat.RelativeTimeFormat")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf