Skip to content

Commit 5ba871a

Browse files
committed
/docs/reference/introspection/counterの翻訳
1 parent 43ca3e3 commit 5ba871a

File tree

2 files changed

+86
-110
lines changed

2 files changed

+86
-110
lines changed

crates/typst-library/src/introspection/counter.rs

Lines changed: 85 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,18 @@ use crate::model::{FigureElem, FootnoteElem, HeadingElem, Numbering, NumberingPa
2121
use crate::routines::Routines;
2222
use crate::World;
2323

24-
/// Counts through pages, elements, and more.
24+
/// ページや要素などの数え上げ。
2525
///
26-
/// With the counter function, you can access and modify counters for pages,
27-
/// headings, figures, and more. Moreover, you can define custom counters for
28-
/// other things you want to count.
26+
/// counter関数を用いることで、ページや見出し、図表などのカウンターにアクセスしたり、修正を加えたりできます。
27+
/// さらに、独自のカウンターを定義して、他のものを数えることもできます。
2928
///
30-
/// Since counters change throughout the course of the document, their current
31-
/// value is _contextual._ It is recommended to read the chapter on [context]
32-
/// before continuing here.
29+
/// カウンターは文書全体を通して変化するため、現在のその値は _コンテキスト依存_ です。
30+
/// 先に進む前に[コンテキスト]($context)の章を読むことをおすすめします。
3331
///
34-
/// # Accessing a counter { #accessing }
35-
/// To access the raw value of a counter, we can use the [`get`]($counter.get)
36-
/// function. This function returns an [array]: Counters can have multiple
37-
/// levels (in the case of headings for sections, subsections, and so on), and
38-
/// each item in the array corresponds to one level.
32+
/// # カウンターへのアクセス { #accessing }
33+
/// [`get`]($counter.get)関数を用いると、生のカウンター値にアクセスできます。
34+
/// この関数は[配列]($array)を返します。
35+
/// カウンターは(節や小節などの見出しの場合に)複数のレベルを持ち、配列の各アイテムが1つのレベルに対応します。
3936
///
4037
/// ```example
4138
/// #set heading(numbering: "1.")
@@ -45,11 +42,10 @@ use crate::World;
4542
/// #context counter(heading).get()
4643
/// ```
4744
///
48-
/// # Displaying a counter { #displaying }
49-
/// Often, we want to display the value of a counter in a more human-readable
50-
/// way. To do that, we can call the [`display`]($counter.display) function on
51-
/// the counter. This function retrieves the current counter value and formats
52-
/// it either with a provided or with an automatically inferred [numbering].
45+
/// # カウンターの表示 { #displaying }
46+
/// しばしば、カウンター値をより人間が読みやすい形で表示したいことがあります。
47+
/// そうするために、カウンターの[`display`]($counter.display)関数を呼び出します。
48+
/// この関数は現在のカウンター値を取得し、与えられた形式か自動的に推論された[番号付け]($numbering)で整形します。
5349
///
5450
/// ```example
5551
/// #set heading(numbering: "1.")
@@ -67,21 +63,19 @@ use crate::World;
6763
/// }
6864
/// ```
6965
///
70-
/// # Modifying a counter { #modifying }
71-
/// To modify a counter, you can use the `step` and `update` methods:
66+
/// # カウンターの変更 { #modifying }
67+
/// `step`および`update`メソッドを用いてカウンターを変更できます。
7268
///
73-
/// - The `step` method increases the value of the counter by one. Because
74-
/// counters can have multiple levels , it optionally takes a `level`
75-
/// argument. If given, the counter steps at the given depth.
69+
/// - `step`メソッドは、カウンター値を1増やします。
70+
/// カウンターは複数のレベルを持つことがあるため、オプションで`level`引数を取ります。
71+
/// `level`が指定された場合、指定された深さのカウンター値を増やします。
7672
///
77-
/// - The `update` method allows you to arbitrarily modify the counter. In its
78-
/// basic form, you give it an integer (or an array for multiple levels). For
79-
/// more flexibility, you can instead also give it a function that receives
80-
/// the current value and returns a new value.
73+
/// - `update`メソッドを用いるとカウンターを任意に変更できます。
74+
/// 通常の形式では、整数(あるいは複数レベルに対しては配列を)与えます。
75+
/// 現在の値を受け取り新しい値を返す関数を代わりに与えると、より柔軟にできます。
8176
///
82-
/// The heading counter is stepped before the heading is displayed, so
83-
/// `Analysis` gets the number seven even though the counter is at six after the
84-
/// second update.
77+
/// 見出しのカウンターは見出しが表示される前にインクリメントされます。
78+
/// そのため、2回目のupdateの後にカウンターが6であったとしても`Analysis`は7になります。
8579
///
8680
/// ```example
8781
/// #set heading(numbering: "1.")
@@ -103,11 +97,11 @@ use crate::World;
10397
/// }
10498
/// ```
10599
///
106-
/// # Page counter
107-
/// The page counter is special. It is automatically stepped at each pagebreak.
108-
/// But like other counters, you can also step it manually. For example, you
109-
/// could have Roman page numbers for your preface, then switch to Arabic page
110-
/// numbers for your main content and reset the page counter to one.
100+
/// # ページカウンター
101+
/// ページカウンターは特別です。
102+
/// 改ページ毎に値がインクリメントされます。
103+
/// しかし、他のカウンターと同様に手動でインクリメントもできます。
104+
/// 例えば、前書きではローマ数字のページ番号を使い、メインのコンテンツではアラビア数字のページ番号に変更し、ページカウンターを1にリセットできます。
111105
///
112106
/// ```example
113107
/// >>> #set page(
@@ -130,9 +124,9 @@ use crate::World;
130124
/// Arabic numbers.
131125
/// ```
132126
///
133-
/// # Custom counters
134-
/// To define your own counter, call the `counter` function with a string as a
135-
/// key. This key identifies the counter globally.
127+
/// # カスタムカウンター
128+
/// 独自のカウンターを定義するには文字列をキーとして`counter`関数を呼び出します。
129+
/// このキーはグローバルにカウンターを識別します。
136130
///
137131
/// ```example
138132
/// #let mine = counter("mycounter")
@@ -143,13 +137,10 @@ use crate::World;
143137
/// #context mine.display()
144138
/// ```
145139
///
146-
/// # How to step
147-
/// When you define and use a custom counter, in general, you should first step
148-
/// the counter and then display it. This way, the stepping behaviour of a
149-
/// counter can depend on the element it is stepped for. If you were writing a
150-
/// counter for, let's say, theorems, your theorem's definition would thus first
151-
/// include the counter step and only then display the counter and the theorem's
152-
/// contents.
140+
/// # インクリメント方法
141+
/// カスタムカウンターを定義して使用する場合、一般にカウンターを最初にインクリメントしてから表示するべきです。
142+
/// こうすることで、カウンターのインクリメント動作をインクリメントする要素に依存させることができます。
143+
/// 例えばtheoremのカウンターを実装する場合、theoremの定義では最初にカウンターのstepを書いてインクリメントを行い、その後に初めてカウンターとtheoremの内容を表示します。
153144
///
154145
/// ```example
155146
/// #let c = counter("theorem")
@@ -163,20 +154,17 @@ use crate::World;
163154
/// #theorem[$2 < 3$]
164155
/// ```
165156
///
166-
/// The rationale behind this is best explained on the example of the heading
167-
/// counter: An update to the heading counter depends on the heading's level. By
168-
/// stepping directly before the heading, we can correctly step from `1` to
169-
/// `1.1` when encountering a level 2 heading. If we were to step after the
170-
/// heading, we wouldn't know what to step to.
157+
/// この背景にある考え方は、見出しカウンターの例で説明するのが最適です。
158+
/// 見出しカウンターの更新は、その見出しのレベルに依存します。
159+
/// 見出しの直前にインクリメントすることで、第2レベルの見出しがあるときに`1`から`1.1`へと正しく更新できます。
160+
/// もし見出しの後にインクリメントする場合、どれをインクリメントするのかわかりません。
171161
///
172-
/// Because counters should always be stepped before the elements they count,
173-
/// they always start at zero. This way, they are at one for the first display
174-
/// (which happens after the first step).
162+
/// カウンターは常に数える要素の前にインクリメントすべきなため、必ず0始まりです。
163+
/// このようにして、(最初のインクリメントの後に)最初に表示されるときには1になります。
175164
///
176-
/// # Time travel
177-
/// Counters can travel through time! You can find out the final value of the
178-
/// counter before it is reached and even determine what the value was at any
179-
/// particular location in the document.
165+
/// # タイムトラベル
166+
/// カウンターはタイムトラベルができます!
167+
/// カウンターの最終的な値を実際に到達する前に知ることができますし、文書の任意の特定の場所での値がどうなっていたかさえ決定できます。
180168
///
181169
/// ```example
182170
/// #let mine = counter("mycounter")
@@ -197,10 +185,9 @@ use crate::World;
197185
/// #mine.step()
198186
/// ```
199187
///
200-
/// # Other kinds of state { #other-state }
201-
/// The `counter` type is closely related to [state] type. Read its
202-
/// documentation for more details on state management in Typst and why it
203-
/// doesn't just use normal variables for counters.
188+
/// # その他の状態 { #other-state }
189+
/// `counter`型は[state]型と密接に関係しています。
190+
/// Typstにおける状態管理のより詳しい詳細と、なぜ単に普通の変数をカウンターに用いないのかについてはstateのドキュメントを参照してください。
204191
#[ty(scope)]
205192
#[derive(Debug, Clone, PartialEq, Hash)]
206193
pub struct Counter(CounterKey);
@@ -404,27 +391,26 @@ impl Counter {
404391

405392
#[scope]
406393
impl Counter {
407-
/// Create a new counter identified by a key.
394+
/// キーで識別される新しいカウンターの作成。
408395
#[func(constructor)]
409396
pub fn construct(
410-
/// The key that identifies this counter.
397+
/// このcounterを識別するキー。
411398
///
412-
/// - If it is a string, creates a custom counter that is only affected
413-
/// by manual updates,
414-
/// - If it is the [`page`] function, counts through pages,
415-
/// - If it is a [selector], counts through elements that matches with the
416-
/// selector. For example,
417-
/// - provide an element function: counts elements of that type,
418-
/// - provide a [`{<label>}`]($label): counts elements with that label.
399+
/// - 文字列の場合、手動更新の場合にのみ影響を受けるカスタムカウンターを作成します
400+
/// - [`page`]関数の場合、改ページに合わせてカウントされます
401+
/// - [セレクター]($selector)の場合、セレクターにマッチする要素が現れるたびにカウントされます。
402+
/// 例えば
403+
/// - 要素関数が与えられた場合、その型を持つ要素がカウントされます
404+
/// - [`{<label>}`]($label)が与えられた場合、そのラベルを持つ要素がカウントされます
419405
key: CounterKey,
420406
) -> Counter {
421407
Self::new(key)
422408
}
423409

424-
/// Retrieves the value of the counter at the current location. Always
425-
/// returns an array of integers, even if the counter has just one number.
410+
/// 現在の位置でのカウンターの値を取得。
411+
/// カウンターが1つの数値しか持たない場合でも、常に整数の配列を返します。
426412
///
427-
/// This is equivalent to `{counter.at(here())}`.
413+
/// これは`{counter.at(here())}`と等価です。
428414
#[func(contextual)]
429415
pub fn get(
430416
&self,
@@ -436,29 +422,24 @@ impl Counter {
436422
self.at_loc(engine, loc)
437423
}
438424

439-
/// Displays the current value of the counter with a numbering and returns
440-
/// the formatted output.
425+
/// 番号付けされたカウンターの現在の値の表示および戻り値としての整形された出力。
441426
#[func(contextual)]
442427
pub fn display(
443428
self,
444429
engine: &mut Engine,
445430
context: Tracked<Context>,
446431
span: Span,
447-
/// A [numbering pattern or a function]($numbering), which specifies how
448-
/// to display the counter. If given a function, that function receives
449-
/// each number of the counter as a separate argument. If the amount of
450-
/// numbers varies, e.g. for the heading argument, you can use an
451-
/// [argument sink]($arguments).
432+
/// カウンターをどのように表示するか指定する[番号付けのパターンまたは関数]($numbering)。
433+
/// 関数が与えられた場合、カウンターの各数値が別々の引数として関数に渡されます。
434+
/// 見出しの番号付けを関数指定するときなどの、引数の数値の数が変化する場合は[引数シンク]($arguments)が使用できます。
452435
///
453-
/// If this is omitted or set to `{auto}`, displays the counter with the
454-
/// numbering style for the counted element or with the pattern
455-
/// `{"1.1"}` if no such style exists.
436+
/// 省略されるか`{auto}`に設定された場合、カウントする要素に設定された番号付け形式を用いてカウンターを表示します。
437+
/// そのようなスタイルが存在しない場合は`{"1.1"}`というパターン指定でカウンターが表示されます。
456438
#[default]
457439
numbering: Smart<Numbering>,
458-
/// If enabled, displays the current and final top-level count together.
459-
/// Both can be styled through a single numbering pattern. This is used
460-
/// by the page numbering property to display the current and total
461-
/// number of pages when a pattern like `{"1 / 1"}` is given.
440+
/// 有効化された場合、トップレベルのカウンターの現在値と最終値を一緒に表示します。
441+
/// 両者のスタイル設定は1つの番号付けパターンで指定できます。
442+
/// これは、`{"1 / 1"}`のようなパターンが与えられたときに、現在のページ番号と全ページ数を表示するためにページの番号付けプロパティによって使用されます。
462443
#[named]
463444
#[default(false)]
464445
both: bool,
@@ -467,27 +448,26 @@ impl Counter {
467448
self.display_impl(engine, loc, numbering, both, context.styles().ok())
468449
}
469450

470-
/// Retrieves the value of the counter at the given location. Always returns
471-
/// an array of integers, even if the counter has just one number.
451+
/// 指定された位置のカウンター値の取得。
452+
/// カウンターが1つの数値しか持たない場合でも、常に整数の配列を返します。
472453
///
473-
/// The `selector` must match exactly one element in the document. The most
474-
/// useful kinds of selectors for this are [labels]($label) and
475-
/// [locations]($location).
454+
/// `selector`は文書中で厳密に1つだけの要素にマッチしなければなりません。
455+
/// この目的で最も便利なセレクターは[ラベル]($label)と[位置]($location)です。
476456
#[func(contextual)]
477457
pub fn at(
478458
&self,
479459
engine: &mut Engine,
480460
context: Tracked<Context>,
481461
span: Span,
482-
/// The place at which the counter's value should be retrieved.
462+
/// カウンター値を取得する場所。
483463
selector: LocatableSelector,
484464
) -> SourceResult<CounterState> {
485465
let loc = selector.resolve_unique(engine.introspector, context).at(span)?;
486466
self.at_loc(engine, loc)
487467
}
488468

489-
/// Retrieves the value of the counter at the end of the document. Always
490-
/// returns an array of integers, even if the counter has just one number.
469+
/// 文書の終わりでのカウンター値の取得。
470+
/// カウンターが1つの数値しか持たない場合でも、常に整数の配列を返します。
491471
#[func(contextual)]
492472
pub fn final_(
493473
&self,
@@ -505,38 +485,34 @@ impl Counter {
505485
Ok(state)
506486
}
507487

508-
/// Increases the value of the counter by one.
488+
/// カウンター値を1増加。
509489
///
510-
/// The update will be in effect at the position where the returned content
511-
/// is inserted into the document. If you don't put the output into the
512-
/// document, nothing happens! This would be the case, for example, if you
513-
/// write `{let _ = counter(page).step()}`. Counter updates are always
514-
/// applied in layout order and in that case, Typst wouldn't know when to
515-
/// step the counter.
490+
/// updateは、返り値であるコンテンツが文書中に挿入された位置で適用されます。
491+
/// 文書中に出力がなければ何も起こりません!
492+
/// 例えば`{let _ = counter(page).step()}`と書いた場合が、この何も起きないときに該当します。
493+
/// カウンターの更新は常にレイアウト順に適用され、Typstはいつカウンターをインクリメントするのか知りません。
516494
#[func]
517495
pub fn step(
518496
self,
519497
span: Span,
520-
/// The depth at which to step the counter. Defaults to `{1}`.
498+
/// カウンターをインクリメントする深さ。
499+
/// デフォルトは`{1}`です。
521500
#[named]
522501
#[default(NonZeroUsize::ONE)]
523502
level: NonZeroUsize,
524503
) -> Content {
525504
self.update(span, CounterUpdate::Step(level))
526505
}
527506

528-
/// Updates the value of the counter.
507+
/// カウンター値の更新。
529508
///
530-
/// Just like with `step`, the update only occurs if you put the resulting
531-
/// content into the document.
509+
/// `step`と同様に、生成されたコンテンツが文書中に配置されたときに限り更新が行われます。
532510
#[func]
533511
pub fn update(
534512
self,
535513
span: Span,
536-
/// If given an integer or array of integers, sets the counter to that
537-
/// value. If given a function, that function receives the previous
538-
/// counter value (with each number as a separate argument) and has to
539-
/// return the new value (integer or array).
514+
/// 整数または整数の配列が与えられた場合、カウンターをその値に設定します。
515+
/// 関数が与えられた場合、その関数は(各数値を別々の引数として)前のカウンターの値を受け取り、新しい値を(整数または配列で)返さなければなりません。
540516
update: CounterUpdate,
541517
) -> Content {
542518
CounterUpdateElem::new(self.0, update).pack().spanned(span)

website/translation-status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"/docs/reference/visualize/stroke/": "untranslated",
145145
"/docs/reference/visualize/tiling/": "untranslated",
146146
"/docs/reference/introspection/": "untranslated",
147-
"/docs/reference/introspection/counter/": "untranslated",
147+
"/docs/reference/introspection/counter/": "translated",
148148
"/docs/reference/introspection/here/": "untranslated",
149149
"/docs/reference/introspection/locate/": "untranslated",
150150
"/docs/reference/introspection/location/": "untranslated",

0 commit comments

Comments
 (0)