Skip to content

Commit 868af16

Browse files
ultimatilekimushun11013w36zj6
authored
/docs/reference/foundations/functionの翻訳 (#205)
Co-authored-by: Shunsuke KIMURA <[email protected]> Co-authored-by: 3w36zj6 <[email protected]>
1 parent f835b9b commit 868af16

File tree

2 files changed

+51
-71
lines changed

2 files changed

+51
-71
lines changed

crates/typst-library/src/foundations/func.rs

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@ use crate::foundations::{
1616
PluginFunc, Scope, Selector, Type, Value,
1717
};
1818

19-
/// A mapping from argument values to a return value.
19+
/// 引数値から戻り値への写像。
2020
///
21-
/// You can call a function by writing a comma-separated list of function
22-
/// _arguments_ enclosed in parentheses directly after the function name.
23-
/// Additionally, you can pass any number of trailing content blocks arguments
24-
/// to a function _after_ the normal argument list. If the normal argument list
25-
/// would become empty, it can be omitted. Typst supports positional and named
26-
/// arguments. The former are identified by position and type, while the latter
27-
/// are written as `name: value`.
21+
/// 関数名の直後に括弧で囲まれたカンマ区切りの関数の _引数_ のリストを書くことにより関数を呼び出すことができます。
22+
/// 加えて、通常の引数リストの後に任意の数のコンテンツブロック引数を関数に渡すこともできます。
23+
/// 通常の引数リストが空の場合は省略が可能です。
24+
/// Typstは位置引数とキーワード引数をサポートしています。
25+
/// 前者は位置と型によって識別され、後者は`name: value`のように書きます。
2826
///
29-
/// Within math mode, function calls have special behaviour. See the
30-
/// [math documentation]($category/math) for more details.
27+
/// 数式モードでは、関数呼び出しは特殊な振る舞いをします。
28+
/// 詳細は[数式のドキュメント]($category/math)を参照して下さい。
3129
///
32-
/// # Example
30+
/// #
3331
/// ```example
3432
/// // Call a function.
3533
/// #list([A], [B])
@@ -42,47 +40,35 @@ use crate::foundations::{
4240
/// #list[A][B]
4341
/// ```
4442
///
45-
/// Functions are a fundamental building block of Typst. Typst provides
46-
/// functions for a variety of typesetting tasks. Moreover, the markup you write
47-
/// is backed by functions and all styling happens through functions. This
48-
/// reference lists all available functions and how you can use them. Please
49-
/// also refer to the documentation about [set]($styling/#set-rules) and
50-
/// [show]($styling/#show-rules) rules to learn about additional ways you can
51-
/// work with functions in Typst.
43+
/// 関数はTypstにおいて基礎となる構成要素です。
44+
/// Typstは様々な組版タスクに応じた関数を提供しています。
45+
/// さらには、作成されるマークアップの裏側では関数が用いられており、すべてのスタイル設定は関数を介して行われます。
46+
/// このリファレンスでは利用可能なすべての関数とその使い方を示します。
47+
/// Typstで関数をさらに活用する方法については、[setルール]($styling/#set-rules)および[showルール]($styling/#show-rules)のドキュメントも参照して下さい。
5248
///
53-
/// # Element functions
54-
/// Some functions are associated with _elements_ like [headings]($heading) or
55-
/// [tables]($table). When called, these create an element of their respective
56-
/// kind. In contrast to normal functions, they can further be used in [set
57-
/// rules]($styling/#set-rules), [show rules]($styling/#show-rules), and
58-
/// [selectors]($selector).
49+
/// # 要素関数
50+
/// [見出し]($heading)や[表]($table)のような、いくつかの関数は _要素_ と結びついており、呼び出すとその種類に応じた要素を作成します。
51+
/// さらに、通常の関数とは異なり、要素関数は[setルール]($styling/#set-rules)、[showルール]($styling/#show-rules)および [セレクター]($selector)で使用可能です。
5952
///
60-
/// # Function scopes
61-
/// Functions can hold related definitions in their own scope, similar to a
62-
/// [module]($scripting/#modules). Examples of this are
63-
/// [`assert.eq`]($assert.eq) or [`list.item`]($list.item). However, this
64-
/// feature is currently only available for built-in functions.
53+
/// # 関数スコープ
54+
/// 関数は、[モジュール]($scripting/#modules)と同様に自身のスコープ内に関連する定義を保持できます。
55+
/// この例は[`assert.eq`]($assert.eq)や[`list.item`]($list.item)です。
56+
/// しかし、現在この機能が利用可能なのは組み込み関数のみです。
6557
///
66-
/// # Defining functions
67-
/// You can define your own function with a [let binding]($scripting/#bindings)
68-
/// that has a parameter list after the binding's name. The parameter list can
69-
/// contain mandatory positional parameters, named parameters with default
70-
/// values and [argument sinks]($arguments).
58+
/// # ユーザー定義関数
59+
/// [letバインディング]($scripting/#bindings)を用いることで、バインディング名の後に引数リストを持ったユーザー定義関数を定義することができます。
60+
/// 引数リストには必須の位置引数、デフォルト値を持つキーワード引数および[可変長引数]($arguments)を用いることができます。
7161
///
72-
/// The right-hand side of a function binding is the function body, which can be
73-
/// a block or any other expression. It defines the function's return value and
74-
/// can depend on the parameters. If the function body is a [code
75-
/// block]($scripting/#blocks), the return value is the result of joining the
76-
/// values of each expression in the block.
62+
/// 関数バインディングの右辺は関数本体で、ブロックか任意の式です。
63+
/// 関数の戻り値を定義し、引数に依存させることができます。
64+
/// 関数本体が[コードブロック]($scripting/#blocks)の場合、戻り値はブロック内のすべての式を連結させた結果になります。
7765
///
78-
/// Within a function body, the `return` keyword can be used to exit early and
79-
/// optionally specify a return value. If no explicit return value is given, the
80-
/// body evaluates to the result of joining all expressions preceding the
81-
/// `return`.
66+
/// 関数本体内では、`return`キーワードを用いて処理を途中で抜け出したり、必要に応じて戻り値を指定して返したりできます。
67+
/// 戻り値が明示的に与えられない場合、本体は`return`の前の式すべてを連結した結果として評価されます。
8268
///
83-
/// Functions that don't return any meaningful value return [`none`] instead.
84-
/// The return type of such functions is not explicitly specified in the
85-
/// documentation. (An example of this is [`array.push`]).
69+
/// 意味のある値を何も返さない関数は、代わりに[`none`]を返します。
70+
/// このような関数の戻り値の型はドキュメント中では明示的に指定されていません
71+
/// (この例としては[`array.push`]が該当します)。
8672
///
8773
/// ```example
8874
/// #let alert(body, fill: red) = {
@@ -105,33 +91,28 @@ use crate::foundations::{
10591
/// ]
10692
/// ```
10793
///
108-
/// # Importing functions
109-
/// Functions can be imported from one file ([`module`]($scripting/#modules)) into
110-
/// another using `{import}`. For example, assume that we have defined the `alert`
111-
/// function from the previous example in a file called `foo.typ`. We can import
112-
/// it into another file by writing `{import "foo.typ": alert}`.
94+
/// # 関数のインポート
95+
/// 関数は、`{import}`を用いてあるファイル([`module`]($scripting/#modules))から別のファイルにインポートすることができます。
96+
/// 例えば、上記の例にある`alert`関数を`foo.typ`というファイルに定義したとします。
97+
/// この場合、`{import "foo.typ": alert}`と書くことで別のファイルにインポートできます。
11398
///
114-
/// # Unnamed functions { #unnamed }
115-
/// You can also created an unnamed function without creating a binding by
116-
/// specifying a parameter list followed by `=>` and the function body. If your
117-
/// function has just one parameter, the parentheses around the parameter list
118-
/// are optional. Unnamed functions are mainly useful for show rules, but also
119-
/// for settable properties that take functions like the page function's
120-
/// [`footer`]($page.footer) property.
99+
/// # 無名関数 { #unnamed }
100+
/// 引数リストに続けて `=>` と関数本体を指定することで、バインディングを作らずに無名関数も作成できます。
101+
/// もし関数の引数が1つだけならば、引数リストの周りの括弧は必須ではありません。
102+
/// 無名関数は主にshowルールで用いると便利ですが、page関数の[`footer`]($page.footer)プロパティのような、関数を引数に取る設定可能プロパティにも便利です。
121103
///
122104
/// ```example
123105
/// #show "once?": it => [#it #it]
124106
/// once?
125107
/// ```
126108
///
127-
/// # Note on function purity
128-
/// In Typst, all functions are _pure._ This means that for the same
129-
/// arguments, they always return the same result. They cannot "remember" things to
130-
/// produce another value when they are called a second time.
109+
/// # 関数の純粋性に関する注意
110+
/// Typstにおいて関数はすべて _純粋_ です。
111+
/// これは同じ引数からは常に同じ結果が返ってくることを意味します。
112+
/// 純粋関数は2回目の呼び出し時に別の値を生成するために何かを「記憶」することはできません。
131113
///
132-
/// The only exception are built-in methods like
133-
/// [`array.push(value)`]($array.push). These can modify the values they are
134-
/// called on.
114+
/// 唯一の例外は[`array.push(value)`]($array.push)のような組み込みメソッドです。
115+
/// これらは呼び出された対象を変更できます。
135116
#[ty(scope, cast, name = "function")]
136117
#[derive(Clone, Hash)]
137118
#[allow(clippy::derived_hash_with_manual_eq)]
@@ -357,12 +338,12 @@ impl Func {
357338

358339
#[scope]
359340
impl Func {
360-
/// Returns a new function that has the given arguments pre-applied.
341+
/// 指定した引数を事前に適用した新しい関数を返します。
361342
#[func]
362343
pub fn with(
363344
self,
364345
args: &mut Args,
365-
/// The arguments to apply to the function.
346+
/// 関数に適用する引数。
366347
#[external]
367348
#[variadic]
368349
arguments: Vec<Value>,
@@ -374,8 +355,7 @@ impl Func {
374355
}
375356
}
376357

377-
/// Returns a selector that filters for elements belonging to this function
378-
/// whose fields have the values of the given arguments.
358+
/// この関数に属する要素のうち、与えられた引数と同じ値のフィールドを持つものを絞り込むセレクターを返します。
379359
///
380360
/// ```example
381361
/// #show heading.where(level: 2): set text(blue)
@@ -387,7 +367,7 @@ impl Func {
387367
pub fn where_(
388368
self,
389369
args: &mut Args,
390-
/// The fields to filter for.
370+
/// 絞り込むフィールド。
391371
#[variadic]
392372
#[external]
393373
fields: Vec<Value>,

website/translation-status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"/docs/reference/foundations/duration/": "untranslated",
2727
"/docs/reference/foundations/eval/": "untranslated",
2828
"/docs/reference/foundations/float/": "untranslated",
29-
"/docs/reference/foundations/function/": "untranslated",
29+
"/docs/reference/foundations/function/": "translated",
3030
"/docs/reference/foundations/int/": "untranslated",
3131
"/docs/reference/foundations/label/": "untranslated",
3232
"/docs/reference/foundations/module/": "untranslated",

0 commit comments

Comments
 (0)