Skip to content

Commit 5ec5cea

Browse files
committed
Foundations/argumentsの翻訳
1 parent 4e3161c commit 5ec5cea

File tree

1 file changed

+34
-35
lines changed
  • crates/typst-library/src/foundations

1 file changed

+34
-35
lines changed

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

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ use crate::foundations::{
99
cast, func, repr, scope, ty, Array, Dict, FromValue, IntoValue, Repr, Str, Value,
1010
};
1111

12-
/// Captured arguments to a function.
12+
/// 関数に渡される引数。
1313
///
14-
/// # Argument Sinks
15-
/// Like built-in functions, custom functions can also take a variable number of
16-
/// arguments. You can specify an _argument sink_ which collects all excess
17-
/// arguments as `..sink`. The resulting `sink` value is of the `arguments`
18-
/// type. It exposes methods to access the positional and named arguments.
14+
/// # 引数シンク
15+
/// 組み込み関数と同様に、カスタム関数も可変個の引数を受け取れます。
16+
/// 余分にある引数をすべてまとめて受け取る_引数シンク_(キッチンシンクのようにさまざまなも
17+
/// のが流れ込む先) は、`..sink`の形で指定できます。このとき生成される`sink`の値は
18+
/// `arguments`型になります。この型は、位置引数と名前付き引数の両方にアクセスするための
19+
/// メソッドを提供しています。
1920
///
2021
/// ```example
2122
/// #let format(title, ..authors) = {
@@ -29,9 +30,9 @@ use crate::foundations::{
2930
/// #format("ArtosFlow", "Jane", "Joe")
3031
/// ```
3132
///
32-
/// # Spreading
33-
/// Inversely to an argument sink, you can _spread_ arguments, arrays and
34-
/// dictionaries into a function call with the `..spread` operator:
33+
/// # 引数の展開
34+
/// 引数シンクとは逆に、`..spread`演算子を使うと、を関数呼び出しにおいて引数や配列、
35+
/// 辞書を展開して渡すことができます。
3536
///
3637
/// ```example
3738
/// #let array = (2, 3, 5)
@@ -43,15 +44,15 @@ use crate::foundations::{
4344
#[derive(Clone, Hash)]
4445
#[allow(clippy::derived_hash_with_manual_eq)]
4546
pub struct Args {
46-
/// The callsite span for the function. This is not the span of the argument
47-
/// list itself, but of the whole function call.
47+
/// 関数呼び出し箇所のスパン。これは引数リスト自体のスパンではなく、
48+
/// 関数呼び出し全体のものです。
4849
pub span: Span,
4950
/// The positional and named arguments.
5051
pub items: EcoVec<Arg>,
5152
}
5253

5354
impl Args {
54-
/// Create positional arguments from a span and values.
55+
/// スパンと値から位置引数を作成します。
5556
pub fn new<T: IntoValue>(span: Span, values: impl IntoIterator<Item = T>) -> Self {
5657
let items = values
5758
.into_iter()
@@ -64,20 +65,20 @@ impl Args {
6465
Self { span, items }
6566
}
6667

67-
/// Attach a span to these arguments if they don't already have one.
68+
/// 引数にスパンがアタッチされていない場合はアタッチします。
6869
pub fn spanned(mut self, span: Span) -> Self {
6970
if self.span.is_detached() {
7071
self.span = span;
7172
}
7273
self
7374
}
7475

75-
/// Returns the number of remaining positional arguments.
76+
/// 残りの位置引数の個数を返します。
7677
pub fn remaining(&self) -> usize {
7778
self.items.iter().filter(|slot| slot.name.is_none()).count()
7879
}
7980

80-
/// Insert a positional argument at a specific index.
81+
/// 指定したインデックスに一引数を挿入します。
8182
pub fn insert(&mut self, index: usize, span: Span, value: Value) {
8283
self.items.insert(
8384
index,
@@ -89,7 +90,7 @@ impl Args {
8990
)
9091
}
9192

92-
/// Push a positional argument.
93+
/// 位置引数をプッシュします。
9394
pub fn push(&mut self, span: Span, value: Value) {
9495
self.items.push(Arg {
9596
span: self.span,
@@ -98,7 +99,7 @@ impl Args {
9899
})
99100
}
100101

101-
/// Consume and cast the first positional argument if there is one.
102+
/// 最初の位置引数がある場合、それを取り出してキャストします。
102103
pub fn eat<T>(&mut self) -> SourceResult<Option<T>>
103104
where
104105
T: FromValue<Spanned<Value>>,
@@ -113,7 +114,7 @@ impl Args {
113114
Ok(None)
114115
}
115116

116-
/// Consume n positional arguments if possible.
117+
/// 可能ならn個数の位置引数を取り出します。
117118
pub fn consume(&mut self, n: usize) -> SourceResult<Vec<Arg>> {
118119
let mut list = vec![];
119120

@@ -133,10 +134,9 @@ impl Args {
133134
Ok(list)
134135
}
135136

136-
/// Consume and cast the first positional argument.
137+
/// 最初の位置引数を取り出してキャストする。
137138
///
138-
/// Returns a `missing argument: {what}` error if no positional argument is
139-
/// left.
139+
/// 位置変数が残っていなければ、`missing argument: {what}`エラーを返します。
140140
pub fn expect<T>(&mut self, what: &str) -> SourceResult<T>
141141
where
142142
T: FromValue<Spanned<Value>>,
@@ -147,7 +147,7 @@ impl Args {
147147
}
148148
}
149149

150-
/// The error message for missing arguments.
150+
/// 引数が足りない場合のエラーメッセージ。
151151
fn missing_argument(&self, what: &str) -> SourceDiagnostic {
152152
for item in &self.items {
153153
let Some(name) = item.name.as_deref() else { continue };
@@ -295,9 +295,9 @@ impl Args {
295295

296296
#[scope]
297297
impl Args {
298-
/// Construct spreadable arguments in place.
298+
/// 展開可能な引数をその場で生成します。
299299
///
300-
/// This function behaves like `{let args(..sink) = sink}`.
300+
/// この関数は、`{let args(..sink) = sink}`のように動作します。
301301
///
302302
/// ```example
303303
/// #let args = arguments(stroke: red, inset: 1em, [Body])
@@ -306,27 +306,26 @@ impl Args {
306306
#[func(constructor)]
307307
pub fn construct(
308308
args: &mut Args,
309-
/// The arguments to construct.
309+
/// 作成する引数。
310310
#[external]
311311
#[variadic]
312312
arguments: Vec<Value>,
313313
) -> Args {
314314
args.take()
315315
}
316316

317-
/// Returns the positional argument at the specified index, or the named
318-
/// argument with the specified name.
317+
/// 指定したインデックスの位置引数、または指定した名前の名前つき引数を返します。
319318
///
320-
/// If the key is an [integer]($int), this is equivalent to first calling
321-
/// [`pos`]($arguments.pos) and then [`array.at`]. If it is a [string]($str),
322-
/// this is equivalent to first calling [`named`]($arguments.named) and then
323-
/// [`dictionary.at`].
319+
/// キーが[整数型]($int)の場合、それはまず[`pos`]($arguments.pos)メソッドを呼んでから、
320+
/// 次に[`array.at`]を呼ぶのと同等です。キーが[文字列型]($str)である場合、
321+
/// まず[`named`]($arguments.named)メソッドを呼び、次に[`dictionary.at`]を
322+
/// 呼ぶのと同等です。
324323
#[func]
325324
pub fn at(
326325
&self,
327-
/// The index or name of the argument to get.
326+
/// 取得する引数のインデックスまたは名前。
328327
key: ArgumentKey,
329-
/// A default value to return if the key is invalid.
328+
/// キーが無効な場合に返すデフォルト値。
330329
#[named]
331330
default: Option<Value>,
332331
) -> StrResult<Value> {
@@ -336,7 +335,7 @@ impl Args {
336335
.ok_or_else(|| missing_key_no_default(key))
337336
}
338337

339-
/// Returns the captured positional arguments as an array.
338+
/// 受け取った位置引数を配列の形で返します。
340339
#[func(name = "pos", title = "Positional")]
341340
pub fn to_pos(&self) -> Array {
342341
self.items
@@ -346,7 +345,7 @@ impl Args {
346345
.collect()
347346
}
348347

349-
/// Returns the captured named arguments as a dictionary.
348+
/// 受け取った名前つき引数を辞書の形で返します。
350349
#[func(name = "named")]
351350
pub fn to_named(&self) -> Dict {
352351
self.items

0 commit comments

Comments
 (0)