Scratch 3.0 확장블럭 다국어 지원

Scratch 3.0은 다국어를 지원한다. 인터페이스에서부터 블럭까지 모든 부분을 다국어를 지원하도록 만들수 있다. 이를 위해선 scratch-l10n 을 수정하여야 한다.

먼저 지난번 개발환경 구축과 마찬가지로 scratch-l10n을 클론하여 사용한다. 지난번 Scratch 개발 공간 내에 다음과 같이 입력한다.

$ git clone https://github.com/byeongkyu/scratch-l10n.git
$ cd scratch-l10n
$ npm install
$ npm link

이제 scratch-gui가 local에 있는 scratch-l10n을 사용하도록 연결하여 준다.

$ cd scratch-gui
$ npm install
$ npm link scratch-l10n scratch-blocks scratch-vm
/Users/byeongkyu/Developer/scratch/scratch-gui/node_modules/scratch-blocks -> /usr/local/lib/node_modules/scratch-blocks -> /Users/byeongkyu/Developer/scratch/scratch-blocks
/Users/byeongkyu/Developer/scratch/scratch-gui/node_modules/scratch-vm -> /usr/local/lib/node_modules/scratch-vm -> /Users/byeongkyu/Developer/scratch/scratch-vm
/Users/byeongkyu/Developer/scratch/scratch-gui/node_modules/scratch-l10n -> /usr/local/lib/node_modules/scratch-l10n -> /Users/byeongkyu/Developer/scratch/scratch-l10n

확장카드

먼저 확장카드에 대한 부분을 수정해보록 한다. 지난번 설명했던 바와 같이, 확장카드는 scratch/scratch-gui/src/lib/libraries/extensions/index.jsx 파일 내에 위치한다. Edubot의 경우엔 다음과 같이 되어 있다.

    {
        name: 'OROCA Edubot',
        extensionId: 'edubot',
        collaborator: 'OROCA',
        iconURL: edubotImage,
        insetIconURL: edubotMenuImage,
        description: (
            <FormattedMessage
                defaultMessage="Play with powerful small robot!"
                description="Description for the 'OROCA_Edubot' extension"
                id="gui.extension.edubot.description"
            />
        ),
        featured: true,
        disabled: false,
        bluetoothRequired: true,
        launchPeripheralConnectionFlow: true,
        useAutoScan: false,
        peripheralImage: edubotPeripheralImage,
        smallPeripheralImage: edubotMenuImage,
        connectingMessage: (
            <FormattedMessage
                defaultMessage="Connecting"
                description="Message to help people connect to their edubot."
                id="gui.extension.edubot.connectingMessage"
            />
        ),
        helpLink: 'https://github.com/oroca/OROCA-EduBot'
    },

여기에서 다국어 지원이 가능한 부분은 description의 “Play with powerful small robot!”과 connectingMessage의 “Connecting”이다. 이 부분은 각각 gui.extension.edubot.description과 gui.extension.edubot.connectingMessage와 같은 id를 가지고 있다.

이제 다시 scratch-l10n으로 가서 다음의 경로에 있는 파일을 수정한다.

scratch/scratch-l10n/editor/interface/en.js

파일을 열고, 임의의 곳에 다음과 같이 입력한다.

    "gui.extension.edubot.description": "Play with powerful small robot!",
    "gui.extension.edubot.connectingMessage": "Connecting",

이제 한국어를 지원하게 하려면, 같은 경로의 ko.js 파일을 열고 다음과 같이 입력한다.

    "gui.extension.edubot.description": "조그맣지만 강력한 로봇과 놀아보세요.",
    "gui.extension.edubot.connectingMessage": "연결 중",

저장한 다음, 빌드한다. 실제로 빌드를 하여야 scratch-gui에서 사용할 수 있는 파일이 만들어진다.

$ cd scratch/scratch-l10n
$ npm run-script build

빌드 과정이 완료되면, dist와 locales 디렉토리가 생성되고 위에서 수정된 내용을 반영하여 파일을 만들어준다. 이제 Scratch를 실행하고, 잘 적용되었는지 확인해본다.

다국어의 선택은 왼쪽 상단의 지구본 모양을 눌러서 선택한다.

먼저 영어 버전은 다음과 같다.

다음으로 인터페이스를 한국어로 바꾸면,

한글도 잘 적용됨을 볼 수 있다.


확장블럭

블럭들도 위와 마찬가지로 각 요소별로 id를 가지고 있다. 이 id를 각 언어에 맞추어 작성해주면 된다. 반복 작업이 대부분이므로 한가지 예만 들어보도록 한다. Edubot의 블럭 중 버튼에 관련된 다음의 블럭에 대해 한국어로 표시되게끔 해보도록 한다.

위 블럭에 대한 서술은 scratch/scratch-vm/src/extensions/scratch3_edubot/index.js 파일에 있다. getInfo() 함수 내에

                {
                    opcode: 'whenButtonPressed',
                    text: formatMessage({
                        id: 'edubot.whenButtonPressed',
                        default: 'when button pressed',
                        description: 'when the button on the edubot is pressed'
                    }),
                    blockType: BlockType.HAT,
                    arguments: {
                    }
                },
                {
                    opcode: 'isButtonPressed',
                    text: formatMessage({
                        id: 'edubot.isButtonPressed',
                        default: 'button pressed?',
                        description: 'is the button on the edubot pressed?'
                    }),
                    blockType: BlockType.BOOLEAN,
                    arguments: {
                    }
                },

와 같이 되어 있는데, 좀 전과 마찬가지로 각 텍스트에 대해 id가 부여되어 있음을 볼수 있다. 따라서 이에 대한 부분을 수정해주면 된다. 블럭에 관련한 부분은 scratch/scratch-l10n/editor/extensions 디렉토리에 있다. 먼저 영어 대한 부분부터 작성한다. en.js 파일을 열고 임의의 위치에 다음과 같이 입력한다.

    "edubot.whenButtonPressed": "when button pressed",
    "edubot.isButtonPressed": "button pressed?",

다음으로 한국어에 대한 부분은 ko.js 파일을 열고 임의의 위치에 다음과 같이 입력한다.

    "edubot.whenButtonPressed": "버튼이 눌리면",
    "edubot.isButtonPressed": "버튼이 눌러졌는가?",

수정된 파일을 저장하고, 위와 마찬가지고 빌드 작업을 진행한다.

$ cd scratch/scratch-l10n
$ npm run-script build

이제 Scratch를 다시 실행해보면,

잘 적용이 됨을 볼수 있다. 끝!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.