LoginSignup
3
2

More than 3 years have passed since last update.

AlexaスキルのHelloWorldテンプレートを日本語化する

Last updated at Posted at 2020-05-17

はじめに

Alexa Skills Kitコマンドラインインターフェース(ASK CLI)を使うとテンプレートから新しいスキルを作ることができますが、そのテンプレートの中のHelloWorldスキルは現状US版になっています。
グローバル対応させるつもりがないときは日本語化しておきたいため、変更内容をメモしておきます。

なお本記事では触れませんが、HelloWorld以外のテンプレートは日本語も含め多言語化されているので、そこから日本語以外を削る、という方法でも対応できると思います。

日本語化手順

前提

ask newでスキルのテンプレートが作られているところまでを前提とします。
公式ページ

記事を書くにあたり選択したオプションは以下となります。

ask new
  Please follow the wizard to start your Alexa skill project ->
  ? Choose the programming language you will use to code your skill:  NodeJS
  ? Choose a method to host your skill's backend resources:  AWS with CloudFormation
  ? Choose a template to start with:  Hello world             Alexa's hello world skill to send the greetings to the world!
  ? Please type in your skill name:  skill-sample-nodejs-hello-world
  ? Please type in your folder name for the skill project (alphanumeric):  Helloworld
  Project for skill "skill-sample-nodejs-hello-world" is successfully created at C:\Users\xxx\xxx\Helloworld

  Project initialized with deploy delegate "@ask-cli/cfn-deployer" successfully.

変更箇所一覧

変更箇所の一覧は以下です。

階層 ファイル 変更内容
. ask-resources.json ・AWSのリージョンを修正
. .gitignore ・git管理不要なファイルを追記
skill-package skill.json ・ロケールを日本に修正
skill-package/assets en-US_largeIcon.png
en-US_smallIcon.png
・リネーム
skill-package/interactionModels/custom en-US.json ・リネーム
・発話を日本語化

初回のデプロイは上記変更の後に行うのがよいかと思います。
日本語化前にいきなりask deployをしてしまうとAWSの米国リージョンにデプロイされてしまい、東京リージョンだけ見ていると見つけられない&日本語化後に米国リージョンのリソースを消さなくてはいけない、ということが起きるためです。

変更内容詳細

それぞれの変更内容の詳細は以下です。

ask-resources.json

"awsRegion"をap-northeast-1にしておきます。これにより、東京リージョンにデプロイされるようになります。

ask-resources.json
{
  "askcliResourcesVersion": "2020-03-31",
  "profiles": {
    "default": {
        
      },
      "skillInfrastructure": {
        "userConfig": {
          "runtime": "nodejs10.x",
          "handler": "index.handler",
          "templatePath": ".\\infrastructure\\cfn-deployer\\skill-stack.yaml",
          "awsRegion": "ap-northeast-1"       //  <-- us-east-1から変更
        },
        "type": "@ask-cli/cfn-deployer"
      }
    }
  }
}

.gitignore

日本語化とは直接は関係ないですが、ソースをgit管理する場合は管理不要ファイルを除外しておきます。

node_modules/
package-lock.json
.DS_Store
.ask/*             // ☆ <-- 追加

skill-package/skill.json

スキルの設定全般を管理するファイルです。localeをja-JPにします。
また、日本だけの対応とするため、isAvailableWorldwideをfalseに、distributionCountriesをJPにします。

skill.json
{
  "manifest": {
    "publishingInformation": {
      "locales": {
        "ja-JP": {    //  <-- en-USから修正
          "summary": "Sample Short Description",
          "examplePhrases": [
            "Alexa open hello world",
            "hello",
            "help"
          ],
          "name": "skill-sample-nodejs-hello-world",
          "description": "Sample Full Description"
        }
      },
      "isAvailableWorldwide": false,  //  <-- trueから修正
      "testingInstructions": "Sample Testing Instructions.",
      "category": "KNOWLEDGE_AND_TRIVIA",
      "distributionCountries": ["JP"]    //  <-- "JP"を追加
    },
    "apis": {
      "custom": {}
    },
    "manifestVersion": "1.0"
  }
}

skill.jsonは、スキルを公開するときにはより詳細に書き直す必要があります(説明や発話例を日本語化するなど)。

skill-package/assets/en-US_largeIcon.png、en-US_smallIcon.png

スキル用アイコンの画像ファイルです。そのままでも支障ないですが一応リネームしておきます。
en-US_largeIcon.png、en-US_smallIcon.png
 ↓
ja-JP_largeIcon.png、ja-JP_smallIcon.png

skill-package/interactionModels/custom/en-US.json

en-US.jsonからja-JP.jsonにリネームした上で内容を書き換えます。
スキルの呼び出し名などを日本語にしています(英語のままでも動きますが一応)。

ja-JP.json
{
    "interactionModel": {
        "languageModel": {
            "invocationName": "ハローワールド",  //  <-- hello worldから修正
            "intents": [
                
                {
                    "name": "HelloWorldIntent",
                    "slots": [],
                    "samples": [
                        "こんにちは"     //  <-- hello などから修正
                    ]
                },
                
            ],
            "types": []
        }
    }
  }

このとき、ファイルをUTF-8で保存しないとデプロイ時にエラーになるので注意が必要です。

デプロイ

ここまで変更できたら、ask deployでのデプロイにより、Alexa Developer ConsoleとAWSの東京リージョン上に反映され、日本語化されたスキルを利用できるようになるはずです。

・Alexa Developer Console
alexa.png

・AWS
lambda.png

あとはどんどん書き換えていけばOKです。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2