Skip to content

Commit f4551c9

Browse files
authored
Merge branch 'main' into translate-introspection/state
2 parents 33048ba + 9cb220a commit f4551c9

File tree

6 files changed

+91
-116
lines changed

6 files changed

+91
-116
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,27 @@ use crate::diag::HintedStrResult;
44
use crate::foundations::{func, Context};
55
use crate::introspection::Location;
66

7-
/// Provides the current location in the document.
7+
/// 文書中における現在のロケーションを提供。
88
///
9-
/// You can think of `here` as a low-level building block that directly extracts
10-
/// the current location from the active [context]. Some other functions use it
11-
/// internally: For instance, `{counter.get()}` is equivalent to
12-
/// `{counter.at(here())}`.
9+
/// `here`はアクティブな[コンテキスト]($context)から現在のロケーションを直接取得する低レベルな構成要素と考えることができます。
10+
/// いくつかの他の関数が内部で使用しています。
11+
/// 例えば、`{counter.get()}`は`{counter.at(here())}`と等価です。
1312
///
14-
/// Within show rules on [locatable]($location/#locatable) elements, `{here()}`
15-
/// will match the location of the shown element.
13+
/// [ロケータブル]($location/#locatable)要素に対するshowルールにおいて、`{here()}`は表示する要素のロケーションにマッチします。
1614
///
17-
/// If you want to display the current page number, refer to the documentation
18-
/// of the [`counter`] type. While `here` can be used to determine the physical
19-
/// page number, typically you want the logical page number that may, for
20-
/// instance, have been reset after a preface.
15+
/// 現在のページ番号を表示したい場合は、[`counter`]型のドキュメントを参照してください。
16+
/// `here`は物理的なページ番号を決定できますが、通常は、前書きの後にリセットされるような、論理的なページ番号が必要でしょう。
2117
///
22-
/// # Examples
23-
/// Determining the current position in the document in combination with the
24-
/// [`position`]($location.position) method:
18+
/// # 例
19+
/// [`position`]($location.position)メソッドと組み合わせて文書中での現在位置を決定します。
2520
/// ```example
2621
/// #context [
2722
/// I am located at
2823
/// #here().position()
2924
/// ]
3025
/// ```
3126
///
32-
/// Running a [query] for elements before the current position:
27+
/// 現在位置より前にある要素に対して[クエリ]($query)を実行します。
3328
/// ```example
3429
/// = Introduction
3530
/// = Background
@@ -42,7 +37,7 @@ use crate::introspection::Location;
4237
///
4338
/// = Conclusion
4439
/// ```
45-
/// Refer to the [`selector`] type for more details on before/after selectors.
40+
/// セレクターのbeforeおよびafterに関する詳細は[`selector`]型のドキュメントを参照してください。
4641
#[func(contextual)]
4742
pub fn here(context: Tracked<Context>) -> HintedStrResult<Location> {
4843
context.location()

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ use crate::engine::Engine;
55
use crate::foundations::{func, Context, LocatableSelector};
66
use crate::introspection::Location;
77

8-
/// Determines the location of an element in the document.
8+
/// 文書中の要素のロケーションを特定。
99
///
10-
/// Takes a selector that must match exactly one element and returns that
11-
/// element's [`location`]. This location can, in particular, be used to
12-
/// retrieve the physical [`page`]($location.page) number and
13-
/// [`position`]($location.position) (page, x, y) for that element.
10+
/// 厳密に1つだけの要素にマッチしなければならないセレクターを受け取り、要素の[`location`]を返します。
11+
/// このlocationを用いると、特に、物理的な[`page`]($location.page)番号やその要素の[`position`]($location.position)(ページ番号、x座標、y座標)を取得できます。
1412
///
15-
/// # Examples
16-
/// Locating a specific element:
13+
/// #
14+
/// 特定の要素のロケーションを特定します。
1715
/// ```example
1816
/// #context [
1917
/// Introduction is at: \
@@ -26,13 +24,12 @@ use crate::introspection::Location;
2624
pub fn locate(
2725
engine: &mut Engine,
2826
context: Tracked<Context>,
29-
/// A selector that should match exactly one element. This element will be
30-
/// located.
27+
/// 厳密に1つだけの要素にマッチしなければならないセレクター。
28+
/// その要素のロケーションが決定されます。
3129
///
32-
/// Especially useful in combination with
33-
/// - [`here`] to locate the current context,
34-
/// - a [`location`] retrieved from some queried element via the
35-
/// [`location()`]($content.location) method on content.
30+
/// 以下との組み合わせが特に便利です。
31+
/// - [`here`]と組み合わせた現在のコンテキストでのロケーションの特定
32+
/// - 何らかのクエリで得られた要素からコンテンツの[`location()`]($content.location)メソッドを用いて取得した[`location`]
3633
selector: LocatableSelector,
3734
) -> HintedStrResult<Location> {
3835
selector.resolve_unique(engine.introspector, context)

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

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ use crate::foundations::{func, scope, ty, Repr};
88
use crate::layout::Position;
99
use crate::model::Numbering;
1010

11-
/// Identifies an element in the document.
11+
/// 文書中の要素の識別。
1212
///
13-
/// A location uniquely identifies an element in the document and lets you
14-
/// access its absolute position on the pages. You can retrieve the current
15-
/// location with the [`here`] function and the location of a queried or shown
16-
/// element with the [`location()`]($content.location) method on content.
13+
/// locationは文書中の要素を一意に識別し、ページ中での絶対位置へのアクセスを提供します。
14+
/// [`here`]関数を用いて現在のロケーションを取得可能です。
15+
/// また、検索したロケーションや表示された要素のロケーションは、コンテンツの[`location()`]($content.location)メソッドを使って取得できます。
1716
///
18-
/// # Locatable elements { #locatable }
19-
/// Currently, only a subset of element functions is locatable. Aside from
20-
/// headings and figures, this includes equations, references, quotes and all
21-
/// elements with an explicit label. As a result, you _can_ query for e.g.
22-
/// [`strong`] elements, but you will find only those that have an explicit
23-
/// label attached to them. This limitation will be resolved in the future.
17+
/// # ロケータブル要素 { #locatable }
18+
/// 現在、要素関数の一部のみがロケーションを取得可能です。
19+
/// 見出しや図表の他に、数式、参照、引用、全ての明示的なラベルを持つ要素が該当します。
20+
/// したがって、例えば[`strong`]要素に対してクエリが実行 _可能_ ですが、見つかるのは明示的にラベルが付けられたもののみです。
21+
/// この制限は将来的に解消される予定です。
2422
#[ty(scope)]
2523
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
2624
pub struct Location(u128);
@@ -48,16 +46,13 @@ impl Location {
4846

4947
#[scope]
5048
impl Location {
51-
/// Returns the page number for this location.
49+
/// このlocationのページ番号を返します。
5250
///
53-
/// Note that this does not return the value of the [page counter]($counter)
54-
/// at this location, but the true page number (starting from one).
51+
/// このlocationの[ページカウンター]($counter)の値を返すのではなく、(1始まりの)実際のページ番号を返すことに注意してください。
5552
///
56-
/// If you want to know the value of the page counter, use
57-
/// `{counter(page).at(loc)}` instead.
53+
/// ページカウンターの値が知りたい場合は代わりに`{counter(page).at(loc)}`を使用してください。
5854
///
59-
/// Can be used with [`here`] to retrieve the physical page position
60-
/// of the current context:
55+
/// [`here`]と組み合わせることで現在のコンテキストにおける実際のページ番号が取得できます。
6156
/// ```example
6257
/// #context [
6358
/// I am located on
@@ -69,24 +64,20 @@ impl Location {
6964
engine.introspector.page(self)
7065
}
7166

72-
/// Returns a dictionary with the page number and the x, y position for this
73-
/// location. The page number starts at one and the coordinates are measured
74-
/// from the top-left of the page.
67+
/// このlocationのページ番号とx座標とy座標を辞書で返します。
68+
/// ページ番号は1始まりで、座標はページの左上から測ります。
7569
///
76-
/// If you only need the page number, use `page()` instead as it allows
77-
/// Typst to skip unnecessary work.
70+
/// ページ番号のみに興味がある場合は、代わりに`page()`を使用すると不要な処理を省略できます。
7871
#[func]
7972
pub fn position(self, engine: &mut Engine) -> Position {
8073
engine.introspector.position(self)
8174
}
8275

83-
/// Returns the page numbering pattern of the page at this location. This
84-
/// can be used when displaying the page counter in order to obtain the
85-
/// local numbering. This is useful if you are building custom indices or
86-
/// outlines.
76+
/// このlocationのページ番号の番号付けパターンを返します。
77+
/// これにより、ページカウンターの表示する際に、その位置での番号付けを取得できます。
78+
/// これは独自の索引やアウトラインを作成する場合に便利です。
8779
///
88-
/// If the page numbering is set to `{none}` at that location, this function
89-
/// returns `{none}`.
80+
/// そのロケーションのページの番号付けが`{none}`に設定されていた場合、`{none}`を返します。
9081
#[func]
9182
pub fn page_numbering(self, engine: &mut Engine) -> Option<Numbering> {
9283
engine.introspector.page_numbering(self).cloned()

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

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@ use crate::diag::HintedStrResult;
44
use crate::engine::Engine;
55
use crate::foundations::{func, Array, Context, LocatableSelector, Value};
66

7-
/// Finds elements in the document.
7+
/// 文書中の要素の検索。
88
///
9-
/// The `query` functions lets you search your document for elements of a
10-
/// particular type or with a particular label. To use it, you first need to
11-
/// ensure that [context] is available.
9+
/// `query`関数を用いると特定の型やラベルを持った要素を文書内から探すことができます。
10+
/// 使用するにはまず[コンテキスト]($context)が利用可能であることを確かめる必要があります。
1211
///
1312
14-
/// # Finding elements
15-
/// In the example below, we manually create a table of contents instead of
16-
/// using the [`outline`] function.
13+
/// # 要素の探索
14+
/// 以下の例では、[`outline`]を用いる代わりに手動で目次を作成しています。
1715
///
18-
/// To do this, we first query for all headings in the document at level 1 and
19-
/// where `outlined` is true. Querying only for headings at level 1 ensures
20-
/// that, for the purpose of this example, sub-headings are not included in the
21-
/// table of contents. The `outlined` field is used to exclude the "Table of
22-
/// Contents" heading itself.
16+
/// このために、まず第1レベルの見出しで`outlined`がtrueなものを検索します。
17+
/// この例において第1レベルの見出しのみを検索する目的は、第2レベル以下の見出しが目次に含まれないようにすることです。
18+
/// `outlined`フィールドは"Table of Contents"という見出し自身を取り除くために使われます。
2319
///
24-
/// Note that we open a `context` to be able to use the `query` function.
20+
/// `query`関数を使用可能にするために、`context`を作成していることに注意してください。
2521
///
2622
/// ```example
2723
/// >>> #set page(
@@ -62,29 +58,25 @@ use crate::foundations::{func, Array, Context, LocatableSelector, Value};
6258
/// #lorem(18)
6359
/// ```
6460
///
65-
/// To get the page numbers, we first get the location of the elements returned
66-
/// by `query` with [`location`]($content.location). We then also retrieve the
67-
/// [page numbering]($location.page-numbering) and [page
68-
/// counter]($counter/#page-counter) at that location and apply the numbering to
69-
/// the counter.
70-
///
71-
/// # A word of caution { #caution }
72-
/// To resolve all your queries, Typst evaluates and layouts parts of the
73-
/// document multiple times. However, there is no guarantee that your queries
74-
/// can actually be completely resolved. If you aren't careful a query can
75-
/// affect itself—leading to a result that never stabilizes.
76-
///
77-
/// In the example below, we query for all headings in the document. We then
78-
/// generate as many headings. In the beginning, there's just one heading,
79-
/// titled `Real`. Thus, `count` is `1` and one `Fake` heading is generated.
80-
/// Typst sees that the query's result has changed and processes it again. This
81-
/// time, `count` is `2` and two `Fake` headings are generated. This goes on and
82-
/// on. As we can see, the output has a finite amount of headings. This is
83-
/// because Typst simply gives up after a few attempts.
84-
///
85-
/// In general, you should try not to write queries that affect themselves. The
86-
/// same words of caution also apply to other introspection features like
87-
/// [counters]($counter) and [state].
61+
/// ページ番号を取得するために、まず[`location`]($content.location)メソッドを用いて`query`が返す要素のロケーションを取得します。
62+
/// 続けて、その位置にある[ページの番号付け]($location.page-numbering)と[ページカウンター]($counter/#page-counter)を取得し、カウンターに番号付けを適用します。
63+
///
64+
/// # 注意事項 { #caution }
65+
/// 全てのクエリを解決するために、Typstは文書の評価とレイアウトを複数回行います。
66+
/// しかしながら、実際にクエリが完全に解決されるかは保証されません。
67+
/// 注意しないとクエリ自身に影響しうるクエリを書いてしまい、結果が決して収束しなくなります。
68+
///
69+
/// 以下の例では、文書中の全ての見出しを検索し、同じ数だけ見出しを生成しています。
70+
/// 最初は`Real`という見出しが1つだけあります。
71+
/// したがって、`count`は`1`で、`Fake`という見出しが作成されます。
72+
/// Typstはクエリの結果が変わったことに気づき、再度処理を行います。
73+
/// このとき`count`は`2`で、 2つの`Fake`見出しが作成されます。
74+
/// これが延々と続きます。
75+
/// ご覧の通り、出力には有限個の見出ししかありません。
76+
/// これは単にTypstが数回試行した後に諦めるためです。
77+
///
78+
/// 一般に、クエリ自身に影響を与えるようなクエリを書こうとしてはいけません。
79+
/// [カウンター]($counter)や[状態]($state)などの他の内省機能にも同じ注意が必要です。
8880
///
8981
/// ```example
9082
/// = Real
@@ -95,17 +87,16 @@ use crate::foundations::{func, Array, Context, LocatableSelector, Value};
9587
/// }
9688
/// ```
9789
///
98-
/// # Command line queries
99-
/// You can also perform queries from the command line with the `typst query`
100-
/// command. This command executes an arbitrary query on the document and
101-
/// returns the resulting elements in serialized form. Consider the following
102-
/// `example.typ` file which contains some invisible [metadata]:
90+
/// # コマンドラインクエリ
91+
/// `typst query`コマンドを用いてコマンドラインからクエリを実行することもできます。
92+
/// このコマンドは文書上で任意のクエリを実行し、シリアライズされた形で結果の要素を返します。
93+
/// 以下の何らかの不可視の[メタデータ]($metadata)を含んだ`example.typ`ファイルを考えます。
10394
///
10495
/// ```typ
10596
/// #metadata("This is a note") <note>
10697
/// ```
10798
///
108-
/// You can execute a query on it as follows using Typst's CLI:
99+
/// Typst CLIを用いて以下のようにこのファイルに対してクエリを実行できます。
109100
/// ```sh
110101
/// $ typst query example.typ "<note>"
111102
/// [
@@ -117,18 +108,16 @@ use crate::foundations::{func, Array, Context, LocatableSelector, Value};
117108
/// ]
118109
/// ```
119110
///
120-
/// Frequently, you're interested in only one specific field of the resulting
121-
/// elements. In the case of the `metadata` element, the `value` field is the
122-
/// interesting one. You can extract just this field with the `--field`
123-
/// argument.
111+
/// 結果となる要素の特定の1つのフィールドにのみ興味があることが多いです。
112+
/// `metadata`要素の場合、`value`フィールドが興味の対象です。
113+
/// `--field`引数を用いてこのフィールドのみを抽出できます。
124114
///
125115
/// ```sh
126116
/// $ typst query example.typ "<note>" --field value
127117
/// ["This is a note"]
128118
/// ```
129119
///
130-
/// If you are interested in just a single element, you can use the `--one`
131-
/// flag to extract just it.
120+
/// 単一の要素にのみ興味がある場合は、`--one`フラグを用いてその要素のみを抽出できます。
132121
///
133122
/// ```sh
134123
/// $ typst query example.typ "<note>" --field value --one
@@ -138,13 +127,14 @@ use crate::foundations::{func, Array, Context, LocatableSelector, Value};
138127
pub fn query(
139128
engine: &mut Engine,
140129
context: Tracked<Context>,
141-
/// Can be
142-
/// - an element function like a `heading` or `figure`,
143-
/// - a `{<label>}`,
144-
/// - a more complex selector like `{heading.where(level: 1)}`,
145-
/// - or `{selector(heading).before(here())}`.
130+
/// - `heading`や`figure`のような要素関数
131+
/// - `{<label>}`
132+
/// - `{heading.where(level: 1)}`のような、より複雑なセレクター
133+
/// - `{selector(heading).before(here())}`
134+
///
135+
/// が可能です。
146136
///
147-
/// Only [locatable]($location/#locatable) element functions are supported.
137+
/// [ロケータブル]($location/#locatable)要素関数がサポートされています。
148138
target: LocatableSelector,
149139
) -> HintedStrResult<Array> {
150140
context.introspect()?;

docs/glossary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ description: |
2525
| table || データや情報を整理して表示する要素 |
2626
| supplement | 補足語 | [参照]($ref)されるものの種類を指す文字列、「図1」の「図」など |
2727
| numbering | 番号付け | [見出し]($heading/#parameters-numbering)[図表]($figure/#parameters-numbering)[番号付きリスト]($enum/#parameters-numbering)などの番号の書式を定義する方法 |
28+
| location | ロケーション | [ロケーション]($location)を参照 |
29+
| locatable | ロケータブル | [ロケータブル要素]($location/#locatable)を参照 |

website/translation-status.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@
145145
"/docs/reference/visualize/tiling/": "untranslated",
146146
"/docs/reference/introspection/": "translated",
147147
"/docs/reference/introspection/counter/": "translated",
148-
"/docs/reference/introspection/here/": "untranslated",
149-
"/docs/reference/introspection/locate/": "untranslated",
150-
"/docs/reference/introspection/location/": "untranslated",
148+
"/docs/reference/introspection/here/": "translated",
149+
"/docs/reference/introspection/locate/": "translated",
150+
"/docs/reference/introspection/location/": "translated",
151151
"/docs/reference/introspection/metadata/": "translated",
152-
"/docs/reference/introspection/query/": "untranslated",
152+
"/docs/reference/introspection/query/": "translated",
153153
"/docs/reference/introspection/state/": "translated",
154154
"/docs/reference/data-loading/": "translated",
155155
"/docs/reference/data-loading/cbor/": "translated",

0 commit comments

Comments
 (0)