Skip to content

i18n(ja): Update environment-variables.md and part of configuring-astro.md#2134

Merged
sarah11918 merged 5 commits into
withastro:mainfrom
morinokami:i18n-ja-environment-variables
Dec 5, 2022
Merged

i18n(ja): Update environment-variables.md and part of configuring-astro.md#2134
sarah11918 merged 5 commits into
withastro:mainfrom
morinokami:i18n-ja-environment-variables

Conversation

@morinokami
Copy link
Copy Markdown
Member

What kind of changes does this PR include?

  • Translated content

Description

  • Update environment-variables.md.

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 3, 2022

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c1a24cc
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/638c5b87463d6e0009c56143
😎 Deploy Preview https://deploy-preview-2134--astro-docs-2.netlify.app/ja/guides/configuring-astro
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions Bot added the i18n Anything to do with internationalization & translation efforts - ask @YanThomas for help! label Dec 3, 2022
Comment thread src/pages/ja/guides/environment-variables.md Outdated
ベストプラクティスについては、公式の[環境変数の例](https://github.com/withastro/astro/tree/main/examples/env-vars)をご覧ください。

```ini
```ini title=".env"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1145 により title=".env" が追加されました。

Comment on lines -39 to +44
```bash
# .env
```ini title=".env"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同じく #1145 に対応しています。

Comment on lines -84 to +105
```ts
```ts title="src/env.d.ts"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも同じく #1145 に対応します。

Comment on lines +20 to +32
:::caution
`import.meta.env`と`.env`ファイルは[設定ファイル](/ja/guides/configuring-astro/#environment-variables)の中では利用できません
:::

## デフォルト環境変数

Astroでは、いくつかの環境変数をすぐに利用できます。

- `import.meta.env.MODE` (`development` | `production`): サイトが動作しているモードです。これは`astro dev`を実行している場合は`development`で、`astro build`を実行している場合は`production`になります。
- `import.meta.env.BASE_URL` (`string`): あなたのサイトの配信元のベースURLです。これは、[`base`オプション](/ja/reference/configuration-reference/#base)によって決まります
- `import.meta.env.PROD` (`boolean`): あなたのサイトが本番環境で動作しているかどうかです
- `import.meta.env.DEV` (`boolean`): 開発中のサイトかどうかです(常に`import.meta.env.PROD`の反対)
- `import.meta.env.SITE` (`string`): プロジェクトの`astro.config`で指定された[`site`オプション](/ja/reference/configuration-reference/#site).
- `import.meta.env.MODE`: サイトが動作しているモードです。これは`astro dev`を実行している場合は`development`で、`astro build`を実行している場合は`production`になります。
- `import.meta.env.PROD`: あなたのサイトが本番環境で動作している場合は`true`となり、その他の場合は`false`となります
- `import.meta.env.DEV`: あなたのサイトが開発環境で動作している場合は`true`となり、その他の場合は`false`となります。常に`import.meta.env.PROD`の反対となります
- `import.meta.env.BASE_URL`: あなたのサイトの配信元のベースURLです。これは、[`base`オプション](/ja/reference/configuration-reference/#base)によって決まります
- `import.meta.env.SITE`: プロジェクトの`astro.config`で指定された[`site`オプション](/ja/reference/configuration-reference/#site)がセットされます。
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1567 に対応しています。

Comment on lines -47 to +77
```ini
.env # すべてのケースで読み込まれます。
.env.local # すべてのケースで読み込まれ、gitにはignoreされます。
.env.[mode] # 指定したモードのみで読み込まれます。
.env.[mode].local # 指定したモードのみで読み込まれ、gitにはignoreされます。
```
`.env`ファイルについてさらに知りたい場合は、[Viteのドキュメントを参照してください](https://vitejs.dev/guide/env-and-mode.html#env-files)。

### CLIの利用

プロジェクトの実行時に環境変数を追加することも可能です。

<PackageManagerTabs>
<Fragment slot="yarn">
```shell
POKEAPI=https://pokeapi.co/api/v2 yarn run dev
```
</Fragment>
<Fragment slot="npm">
```shell
POKEAPI=https://pokeapi.co/api/v2 npm run dev
```
</Fragment>
<Fragment slot="pnpm">
```shell
POKEAPI=https://pokeapi.co/api/v2 pnpm run dev
```
</Fragment>
</PackageManagerTabs>

:::caution
このようにセットされた変数は、クライアントサイドも含め、プロジェクトの任意の箇所から利用可能となります。
:::
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも #1567 に対応しています。

Comment on lines +36 to +37
### `.env`ファイル

Copy link
Copy Markdown
Member Author

@morinokami morinokami Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1567 に対応しています。

Comment on lines -64 to +85
```js
```js /(?<!//.*)import.meta.env.[A-Z_]+/
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1178 に対応しています。

Comment on lines -8 to +9
Astroは環境変数にViteを使用しています。[Viteのいずれかの方法](https://vitejs.dev/guide/env-and-mode.html)で環境変数の取得や設定ができます
Astroは環境変数に関するViteの組み込みのサポートを利用しています。環境変数を扱うために[Viteが備える任意の方式](https://vitejs.dev/guide/env-and-mode.html)を使用できます
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1567 に対応しています。


サーバ側のコードでは _すべて_ の環境変数が使えますが、クライアント側のコードではセキュリティのために`PUBLIC_`というプレフィックスを持つ環境変数のみが使えることに注意してください。

ベストプラクティスについては、公式の[環境変数の例](https://github.com/withastro/astro/tree/main/examples/env-vars)をご覧ください。
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1531 により削除されました。

Comment thread src/pages/ja/guides/environment-variables.md Outdated
Comment on lines +109 to +114
## 環境変数

Astroは他のファイルをロードする前に設定ファイルを評価します。そのため、`import.meta.env`を使うことはできず、また`.env`ファイルによってセットされた環境変数を取得することもできません。

設定ファイルの中で`process.env`を使用して、[CLIによりセットされた](/ja/guides/environment-variables/#cliの利用)ものなど、その他の環境変数を取得することは可能です。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`import.meta.env` and `.env` files are not available inside [configuration files](/en/guides/configuring-astro/#environment-variables).
に対応する日本語版のリンク先が存在せず、しかし /en で始まるもとのリンク先のままとすると CI のエラーとなってしまうため、急遽こちらの訳のみ追加しました。configuring-astro.md 全体としては英語版と比較して未訳箇所が残っているようです。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuring-astro.md も早めに更新が必要そうですね。今回は関連する場所だけで大丈夫だと思います。

@morinokami morinokami changed the title i18n(ja): Update environment-variables.md i18n(ja): Update environment-variables.md and part of configuring-astro.md Dec 3, 2022
@morinokami morinokami marked this pull request as ready for review December 3, 2022 13:05
Copy link
Copy Markdown
Contributor

@kyosuke kyosuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morinokami レビューしました!最新の変更が丁寧に反映されていて、またコメントで変更元もいただいていたのでレビューしやすかったです。
configuring-astro.md のほうだけ、こうした方が読みやすいかなという小さなコメントを入れていますが、このままでも問題ないと思います。

Comment on lines +109 to +114
## 環境変数

Astroは他のファイルをロードする前に設定ファイルを評価します。そのため、`import.meta.env`を使うことはできず、また`.env`ファイルによってセットされた環境変数を取得することもできません。

設定ファイルの中で`process.env`を使用して、[CLIによりセットされた](/ja/guides/environment-variables/#cliの利用)ものなど、その他の環境変数を取得することは可能です。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuring-astro.md も早めに更新が必要そうですね。今回は関連する場所だけで大丈夫だと思います。


## 環境変数

Astroは他のファイルをロードする前に設定ファイルを評価します。そのため、`import.meta.env`を使うことはできず、また`.env`ファイルによってセットされた環境変数を取得することもできません。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Astroは他のファイルをロードする前に設定ファイルを評価します。そのため、`import.meta.env`を使うことはできず、また`.env`ファイルによってセットされた環境変数を取得することもできません
Astroは他のファイルをロードする前に設定ファイルを評価します。そのため、`import.meta.env`は使えず、また`.env`ファイルによってセットされた環境変数を取得もできません

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

環境変数を取得もできません については 環境変数の取得もできません としておきました🙏


Astroは他のファイルをロードする前に設定ファイルを評価します。そのため、`import.meta.env`を使うことはできず、また`.env`ファイルによってセットされた環境変数を取得することもできません。

設定ファイルの中で`process.env`を使用して、[CLIによりセットされた](/ja/guides/environment-variables/#cliの利用)ものなど、その他の環境変数を取得することは可能です。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
設定ファイルの中で`process.env`を使用して、[CLIによりセットされた](/ja/guides/environment-variables/#cliの利用)ものなど、その他の環境変数を取得することは可能です
設定ファイルの中で`process.env`を使用して、[CLIによりセットされた](/ja/guides/environment-variables/#cliの利用)ものなど、その他の環境変数の取得は可能です

@morinokami
Copy link
Copy Markdown
Member Author

@kyosuke レビューいただきありがとうございました!コメントを反映しました🙏

@kyosuke
Copy link
Copy Markdown
Contributor

kyosuke commented Dec 4, 2022

@morinokami 修正対応ありがとうございます!確認しました。LGTM!

@sarah11918
Copy link
Copy Markdown
Member

I saw the magic phrase, so I'm merging! 🥳

@sarah11918 sarah11918 merged commit ed1c1c8 into withastro:main Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n Anything to do with internationalization & translation efforts - ask @YanThomas for help!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants