Skip to content

Commit b1f6851

Browse files
authored
ja: Translate Chapter 25 (Traits) (#1436)
Konnichiwa, JP translation folks #652. Here's a MR for **Traits** chapter. I'm open to suggestions and feedback :) Could you take a look at it? Thank you!
1 parent 4e43ddc commit b1f6851

File tree

1 file changed

+153
-10
lines changed

1 file changed

+153
-10
lines changed

po/ja.po

+153-10
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ msgstr "デフォルトメソッド"
469469

470470
#: src/SUMMARY.md:144 src/traits/trait-bounds.md:1
471471
msgid "Trait Bounds"
472-
msgstr "トレイト境界"
472+
msgstr "トレイト制約"
473473

474474
#: src/SUMMARY.md:145
475475
msgid "impl Trait"
@@ -7611,6 +7611,8 @@ msgstr ""
76117611
msgid ""
76127612
"Rust lets you abstract over types with traits. They're similar to interfaces:"
76137613
msgstr ""
7614+
"Rustでは、型に関しての抽象化をトレイトを用いて行うことができます。トレイトは"
7615+
"インターフェースに似ています:"
76147616

76157617
#: src/traits.md:7 src/traits/trait-objects.md:7
76167618
msgid "// No name needed, cats won't respond anyway.\n"
@@ -7631,20 +7633,80 @@ msgstr ""
76317633
#: src/traits.md:27 src/traits/trait-objects.md:24
76327634
msgid "\"Fido\""
76337635
msgstr ""
7636+
"```rust,editable\n"
7637+
"struct Dog { name: String, age: i8 }\n"
7638+
"struct Cat { lives: i8 } // 猫に名前は必要ありません。どのみち猫は名前に反応"
7639+
"しないからです。\n"
7640+
"\n"
7641+
"trait Pet {\n"
7642+
" fn talk(&self) -> String;\n"
7643+
"}\n"
7644+
"\n"
7645+
"impl Pet for Dog {\n"
7646+
" fn talk(&self) -> String { format!(\"Woof, my name is {}!\", self."
7647+
"name) }\n"
7648+
"}\n"
7649+
"\n"
7650+
"impl Pet for Cat {\n"
7651+
" fn talk(&self) -> String { String::from(\"Miau!\") }\n"
7652+
"}\n"
7653+
"\n"
7654+
"fn greet<P: Pet>(pet: &P) {\n"
7655+
" println!(\"Oh you're a cutie! What's your name? {}\", pet.talk());\n"
7656+
"}\n"
7657+
"\n"
7658+
"fn main() {\n"
7659+
" let captain_floof = Cat { lives: 9 };\n"
7660+
" let fido = Dog { name: String::from(\"Fido\"), age: 5 };\n"
7661+
"\n"
7662+
" greet(&captain_floof);\n"
7663+
" greet(&fido);\n"
7664+
"}\n"
7665+
"```"
76347666

76357667
#: src/traits/trait-objects.md:3
76367668
msgid ""
76377669
"Trait objects allow for values of different types, for instance in a "
76387670
"collection:"
76397671
msgstr ""
7672+
"トレイトオブジェクトは異なる型の値をひとつのコレクションにまとめることを可能"
7673+
"にします:"
76407674

76417675
#: src/traits/trait-objects.md:27
76427676
msgid "\"Hello, who are you? {}\""
76437677
msgstr ""
7678+
"```rust,editable\n"
7679+
"struct Dog { name: String, age: i8 }\n"
7680+
"struct Cat { lives: i8 } // 猫に名前は必要ありません。どのみち猫は名前に反応"
7681+
"しないからです。\n"
7682+
"\n"
7683+
"trait Pet {\n"
7684+
" fn talk(&self) -> String;\n"
7685+
"}\n"
7686+
"\n"
7687+
"impl Pet for Dog {\n"
7688+
" fn talk(&self) -> String { format!(\"Woof, my name is {}!\", self."
7689+
"name) }\n"
7690+
"}\n"
7691+
"\n"
7692+
"impl Pet for Cat {\n"
7693+
" fn talk(&self) -> String { String::from(\"Miau!\") }\n"
7694+
"}\n"
7695+
"\n"
7696+
"fn main() {\n"
7697+
" let pets: Vec<Box<dyn Pet>> = vec![\n"
7698+
" Box::new(Cat { lives: 9 }),\n"
7699+
" Box::new(Dog { name: String::from(\"Fido\"), age: 5 }),\n"
7700+
" ];\n"
7701+
" for pet in pets {\n"
7702+
" println!(\"Hello, who are you? {}\", pet.talk());\n"
7703+
" }\n"
7704+
"}\n"
7705+
"```"
76447706

76457707
#: src/traits/trait-objects.md:32
76467708
msgid "Memory layout after allocating `pets`:"
7647-
msgstr ""
7709+
msgstr "`pets`を割り当てた後のメモリレイアウト:"
76487710

76497711
#: src/traits/trait-objects.md:34
76507712
msgid ""
@@ -7712,18 +7774,24 @@ msgid ""
77127774
"Types that implement a given trait may be of different sizes. This makes it "
77137775
"impossible to have things like `Vec<dyn Pet>` in the example above."
77147776
msgstr ""
7777+
"同じトレイトを実装する型であってもそのサイズは異なることがあります。そのた"
7778+
"め、上の例でVec<dyn Pet>と書くことはできません。"
77157779

77167780
#: src/traits/trait-objects.md:70
77177781
msgid ""
77187782
"`dyn Pet` is a way to tell the compiler about a dynamically sized type that "
77197783
"implements `Pet`."
77207784
msgstr ""
7785+
"`dyn Pet` はコンパイラに、この型が`Pet`トレイトを実装する動的なサイズの型であ"
7786+
"ることを伝えます。"
77217787

77227788
#: src/traits/trait-objects.md:72
77237789
msgid ""
77247790
"In the example, `pets` is allocated on the stack and the vector data is on "
77257791
"the heap. The two vector elements are _fat pointers_:"
77267792
msgstr ""
7793+
"上の例では `pets` はスタックに確保され、ベクターのデータはヒープ上にありま"
7794+
"す。二つのベクターの要素は _ファットポインタ_ です:"
77277795

77287796
#: src/traits/trait-objects.md:74
77297797
msgid ""
@@ -7732,16 +7800,26 @@ msgid ""
77327800
"wikipedia.org/wiki/Virtual_method_table) (vtable) for the `Pet` "
77337801
"implementation of that particular object."
77347802
msgstr ""
7803+
"ファットポインタはdouble-widthポインタです。これは二つの要素からなります:実"
7804+
"際のオブジェクトへのポインタと、そのオブジェクトの`Pet`の実装のための[仮想関"
7805+
"数テーブル](https://ja.wikipedia.org/wiki/"
7806+
"%E4%BB%AE%E6%83%B3%E9%96%A2%E6%95%B0%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB) "
7807+
"(vtable)です。"
77357808

77367809
#: src/traits/trait-objects.md:77
77377810
msgid ""
77387811
"The data for the `Dog` named Fido is the `name` and `age` fields. The `Cat` "
77397812
"has a `lives` field."
77407813
msgstr ""
7814+
"\"Fido\"と名付けられた`Dog`のデータは`name` と `age` のフィールドに対応しま"
7815+
"す。(訳注: \"Fido\"とはよくある犬の愛称で、日本語でいう「ポチ」のような名前"
7816+
"です。)例の`Cat`には`lives` フィールドがあります。(訳注: ここで`Cat`が"
7817+
"`lives`というフィールドを持ち、9で初期化しているのは\"A cat has nine lives\" "
7818+
"—猫は9つの命を持つ—ということわざに由来します。)"
77417819

77427820
#: src/traits/trait-objects.md:79
77437821
msgid "Compare these outputs in the above example:"
7744-
msgstr ""
7822+
msgstr "上の例において、下のコードによる出力結果を比べてみましょう:"
77457823

77467824
#: src/traits/trait-objects.md:81 src/traits/trait-objects.md:82
77477825
#: src/traits/closures.md:54
@@ -7760,10 +7838,12 @@ msgid ""
77607838
"Rust derive macros work by automatically generating code that implements the "
77617839
"specified traits for a data structure."
77627840
msgstr ""
7841+
"Rustのderiveマクロは、データ構造体に対して、指定されたトレイトを実装するコー"
7842+
"ドを自動的に生成します。"
77637843

77647844
#: src/traits/deriving-traits.md:5
77657845
msgid "You can let the compiler derive a number of traits as follows:"
7766-
msgstr ""
7846+
msgstr "コンパイラには、以下のような多くのトレイトを導出させることができます:"
77677847

77687848
#: src/traits/deriving-traits.md:18
77697849
msgid "\"Is {:?}\\nequal to {:?}?\\nThe answer is {}!\""
@@ -7782,6 +7862,7 @@ msgstr ""
77827862
#: src/traits/default-methods.md:3
77837863
msgid "Traits can implement behavior in terms of other trait methods:"
77847864
msgstr ""
7865+
"トレイトでは、別のトレイトメソッドを用いて挙動を定義することが可能です:"
77857866

77867867
#: src/traits/default-methods.md:25
77877868
msgid "\"{a:?} equals {b:?}: {}\""
@@ -7797,34 +7878,46 @@ msgid ""
77977878
"are required to implement themselves. Methods with default implementations "
77987879
"can rely on required methods."
77997880
msgstr ""
7881+
"トレイトは予め実装された(デフォルトの)メソッドと、ユーザが自身で実装する必"
7882+
"要のあるメソッドを指定することができます。デフォルトの実装のあるメソッドは、"
7883+
"その定義を実装必須のメソットに依存することができます。"
78007884

78017885
#: src/traits/default-methods.md:35
78027886
msgid "Move method `not_equals` to a new trait `NotEquals`."
78037887
msgstr ""
7888+
"メソッド `not_equals` を新しいトレイト `NotEquals` に移してみましょう。"
78047889

78057890
#: src/traits/default-methods.md:37
78067891
msgid "Make `Equals` a super trait for `NotEquals`."
7807-
msgstr ""
7892+
msgstr "`Equals` を `NotEquals` のスーパートレイトにしてみましょう。"
78087893

78097894
#: src/traits/default-methods.md:46
78107895
msgid "Provide a blanket implementation of `NotEquals` for `Equals`."
7811-
msgstr ""
7896+
msgstr "`Equals`に対する`NotEquals`のブランケット実装を示してみましょう。"
78127897

78137898
#: src/traits/default-methods.md:58
78147899
msgid ""
78157900
"With the blanket implementation, you no longer need `Equals` as a super "
78167901
"trait for `NotEqual`."
78177902
msgstr ""
7903+
"ブランケット実装を用いれば、`Equals` を`NotEqual`のスーパートレイトとする必要"
7904+
"はなくなります。"
78187905

78197906
#: src/traits/trait-bounds.md:3
78207907
msgid ""
78217908
"When working with generics, you often want to require the types to implement "
78227909
"some trait, so that you can call this trait's methods."
78237910
msgstr ""
7911+
"ジェネリクスを用いるとき、あるトレイトのメソッドを呼び出せるように、型がその"
7912+
"トレイトを実装していることを要求したいことがよくあります。(脚注:本教材では"
7913+
"\"Trait bounds\"を「トレイト制約」と翻訳しましたが、Rustの日本語翻訳コミュニ"
7914+
"ティでは「トレイト境界」と呼ぶ流派もあり、どちらの翻訳を採用するかについては"
7915+
"[議論がなされています](https://github.com/rust-lang-ja/book-ja/"
7916+
"issues/172)。)"
78247917

78257918
#: src/traits/trait-bounds.md:6
78267919
msgid "You can do this with `T: Trait` or `impl Trait`:"
7827-
msgstr ""
7920+
msgstr "そうしたことは`T: Trait` や `impl Trait`を用いて行えます:"
78287921

78297922
#: src/traits/trait-bounds.md:12
78307923
msgid ""
@@ -7847,24 +7940,54 @@ msgstr ""
78477940
#: src/traits/trait-bounds.md:29
78487941
msgid "\"{many_more}\""
78497942
msgstr ""
7943+
"```rust,editable\n"
7944+
"fn duplicate<T: Clone>(a: T) -> (T, T) {\n"
7945+
" (a.clone(), a.clone())\n"
7946+
"}\n"
7947+
"\n"
7948+
"// 以下の糖衣構文です:\n"
7949+
"// fn add_42_millions<T: Into<i32>>(x: T) -> i32 {\n"
7950+
"fn add_42_millions(x: impl Into<i32>) -> i32 {\n"
7951+
" x.into() + 42_000_000\n"
7952+
"}\n"
7953+
"\n"
7954+
"// struct NotClonable;\n"
7955+
"\n"
7956+
"fn main() {\n"
7957+
" let foo = String::from(\"foo\");\n"
7958+
" let pair = duplicate(foo);\n"
7959+
" println!(\"{pair:?}\");\n"
7960+
"\n"
7961+
" let many = add_42_millions(42_i8);\n"
7962+
" println!(\"{many}\");\n"
7963+
" let many_more = add_42_millions(10_000_000);\n"
7964+
" println!(\"{many_more}\");\n"
7965+
"}\n"
7966+
"```"
78507967

78517968
#: src/traits/trait-bounds.md:35
78527969
msgid "Show a `where` clause, students will encounter it when reading code."
78537970
msgstr ""
7971+
"`where` 節の使い方を示しましょう。受講生はコードを読んでいるときに、この"
7972+
"`where`節に遭遇します。"
78547973

78557974
#: src/traits/trait-bounds.md:46
78567975
msgid "It declutters the function signature if you have many parameters."
78577976
msgstr ""
7977+
"たくさんのパラメタがある場合に、`where`節は関数のシグネチャを整理整頓してくれ"
7978+
"ます。"
78587979

78597980
#: src/traits/trait-bounds.md:47
78607981
msgid "It has additional features making it more powerful."
7861-
msgstr ""
7982+
msgstr "`where`節には更に強力な機能があります。"
78627983

78637984
#: src/traits/trait-bounds.md:48
78647985
msgid ""
78657986
"If someone asks, the extra feature is that the type on the left of \":\" can "
78667987
"be arbitrary, like `Option<T>`."
78677988
msgstr ""
7989+
"誰かに聞かれた場合で良いですが、その機能というのは、\":\" の左側には "
7990+
"`Option<T>` のように任意の型を表現できるというものです。"
78687991

78697992
#: src/traits/impl-trait.md:1
78707993
msgid "`impl Trait`"
@@ -7875,28 +7998,35 @@ msgid ""
78757998
"Similar to trait bounds, an `impl Trait` syntax can be used in function "
78767999
"arguments and return values:"
78778000
msgstr ""
8001+
"トレイト境界と似たように、構文 `impl Trait`は関数の引数と返り値においてのみ利"
8002+
"用可能です:"
78788003

78798004
#: src/traits/impl-trait.md:19
78808005
msgid "`impl Trait` allows you to work with types which you cannot name."
7881-
msgstr ""
8006+
msgstr "`impl Trait`を用いれば、型名を明示せずに型を限定することができます。"
78828007

78838008
#: src/traits/impl-trait.md:23
78848009
msgid ""
78858010
"The meaning of `impl Trait` is a bit different in the different positions."
7886-
msgstr ""
8011+
msgstr "`impl Trait`の意味は、位置によって少し異なります。"
78878012

78888013
#: src/traits/impl-trait.md:25
78898014
msgid ""
78908015
"For a parameter, `impl Trait` is like an anonymous generic parameter with a "
78918016
"trait bound."
78928017
msgstr ""
8018+
"パラメタに対しては、`impl Trait`は、トレイト境界を持つ匿名のジェネリックパラ"
8019+
"メタのようなものです。"
78938020

78948021
#: src/traits/impl-trait.md:27
78958022
msgid ""
78968023
"For a return type, it means that the return type is some concrete type that "
78978024
"implements the trait, without naming the type. This can be useful when you "
78988025
"don't want to expose the concrete type in a public API."
78998026
msgstr ""
8027+
"返り値の型に用いる場合は、特定のトレイトを実装する何らかの具象型を返すが、具"
8028+
"体的な型名は明示しないということを意味します。このことは公開されるAPIに具象型"
8029+
"を晒したくない場合に便利です。"
79008030

79018031
#: src/traits/impl-trait.md:31
79028032
msgid ""
@@ -7907,6 +8037,12 @@ msgid ""
79078037
"`let x: Vec<_> = foo.collect()` or with the turbofish, `foo.collect::"
79088038
"<Vec<_>>()`."
79098039
msgstr ""
8040+
"返り値の位置における型推論は困難です。`impl Foo`を返す関数は、それが返す具象"
8041+
"型はソースコードに書かれることないまま、具象型を選びます。`collect<B>() -> B`"
8042+
"のようなジェネリック型を返す関数は、`B`を満たすどのような型でも返すことがあり"
8043+
"ます。 また、関数の呼び出し元はそのような型を一つを選ぶ必要があるかもしれませ"
8044+
"ん。 それは、 `let x: Vec<_> = foo.collect()`としたり、turbofishを用いて`foo."
8045+
"collect::<Vec<_>>()`とすることで行えます。"
79108046

79118047
#: src/traits/impl-trait.md:37
79128048
msgid ""
@@ -7918,6 +8054,13 @@ msgid ""
79188054
"`format!` returns. If we wanted to do the same via `: Display` syntax, we'd "
79198055
"need two independent generic parameters."
79208056
msgstr ""
8057+
"この例は素晴らしい例です。なぜなら、 `impl Display`を2回用いているからで"
8058+
"す。 ここでは `impl Display` の型が同一になることを強制するものはない、という"
8059+
"説明をするのに役立ちます。もし単一の`T: Display`を用いた場合、入力の`T`と返り"
8060+
"値の`T`が同一の型であることが強制されてしまいます。例で示した関数ではうまくい"
8061+
"かないでしょう。なぜなら、我々が期待する入力の型は、`format!`が返すものではお"
8062+
"そらくないからです。もしも同じことを`: Display`の構文で行いたい場合、2つの独"
8063+
"立したジェネリックなパラメタが必要となるでしょう。"
79218064

79228065
#: src/traits/important-traits.md:3
79238066
msgid ""

0 commit comments

Comments
 (0)