Skip to content

Commit

Permalink
More updates... ugh, wish this would work
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Nov 5, 2020
1 parent f85735b commit f41865f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# resource-translator
A GitHub action that uses Azure Cognitive Services translator to generate .resx resource files
# 🌐 Resource translator

A GitHub action that uses Azure Cognitive Services Translator to generate .resx resource files given a source .resx file.

## Usage

```yml
# This is a basic workflow to help you get started with Actions
name: Create translation pull request

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [ main ]
paths:
- '**.resx' # only take action when *.resx files change

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Use the resource translator to automatically translate resource files
- name: Resource translator
uses: IEvangelist/[email protected]
with:
# The Azure Cognitive Services translator resource subscription key
subscriptionKey: ${{ secrets.AZURE_TRANSLATOR_SUBSCRIPTION_KEY }}
# The Azure Cognitive Services translator resource endpoint.
endpoint: ${{ secrets.AZURE_TRANSLATOR_ENDPOINT }}
# (Optional) The Azure Cognitive Services translator resource region. This is optional when using a global translator resource.
region: ${{ secrets.AZURE_TRANSLATOR_REGION }}
# The source locale (i.e.; 'en'), used to create the glob pattern for which resource (**/*.en.resx) files to use as input
sourceLocale: 'en'

- name: Create pull request
uses: peter-evans/[email protected]
```
4 changes: 2 additions & 2 deletions __tests__/resource-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('IO: roundtrip, resolve->read->write->read-> compare', async () => {
expect(resourceXml.root.data[1].value[0]).toEqual('Where have you gone?');
});

test('IO: apply translations', async () => {
test('IO: apply translations to Test.en.resx', async () => {
const resourcePath = resolve(__dirname, './data/Test.en.resx');
let resourceXml = await readFile(resourcePath);

Expand All @@ -57,7 +57,7 @@ test('IO: apply translations', async () => {
expect(resourceXml.root.data[1].value[0]).toEqual('We meet again!');
});

test('IO: apply translations', async () => {
test('IO: apply translations to Index.en.resx', async () => {
const resourcePath = resolve(__dirname, './data/Index.en.resx');
let resourceXml = await readFile(resourcePath);

Expand Down
15 changes: 15 additions & 0 deletions __tests__/translator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,19 @@ test("IO: translatable XML is mapped parses known XML", async () => {
expect(map.get("MyFriend")).toEqual("Where have you gone?");
}
}
});

test('IO: get translatable text map', async () => {
const resourcePath = resolve(__dirname, './data/Index.en.resx');
let resourceXml = await readFile(resourcePath);

const translatableTextMap = await getTranslatableTextMap(resourceXml);

expect(translatableTextMap).toBeTruthy();
expect(translatableTextMap.ordinals).toEqual([0,1,2]);
expect(translatableTextMap.text).toBeTruthy();

expect(translatableTextMap.text.get('Greeting')).toEqual('Welcome to your new app.');
expect(translatableTextMap.text.get('HelloWorld')).toEqual('Hello, world!');
expect(translatableTextMap.text.get('SurveyTitle')).toEqual('How is Blazor working for you?.');
});
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Resource translator'
description: 'A GitHub action that uses Azure Cognitive Services translator to generate .resx resource files'
description: 'A GitHub action that uses Azure Cognitive Services Translator to generate .resx resource files given a source .resx file.'
branding:
icon: flag
color: gray-dark
inputs:
subscriptionKey:
description: 'The Azure Cognitive Services translator resource subscription key.'
Expand All @@ -13,9 +16,6 @@ inputs:
sourceLocale:
description: 'The source locale (i.e.; ''en''), used to create the glob pattern for which resource (**/*.en.resx) files to use as input'
required: false
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'node12'
main: 'dist/resource-translator/index.js'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ievangelist/resource-translator",
"version": "1.0.2-preview",
"version": "1.0.2-preview1",
"preview": true,
"keywords": [
"github",
Expand Down

0 comments on commit f41865f

Please sign in to comment.