Git Product home page Git Product logo

ievangelist / resource-translator Goto Github PK

View Code? Open in Web Editor NEW
51.0 10.0 11.0 1.56 MB

A GitHub Action that automatically creates machine-translated PRs of translation files. Supported file formats include, .ini, .po, .restext, .resx, .xliff .json.

License: MIT License

TypeScript 99.15% JavaScript 0.85%
xliff2 ini portable-object restext resx machine-translator ai cognitive-services github-actions localization

resource-translator's Introduction

๐ŸŒ Machine Translator

All Contributors

GitHub Marketplace build

A GitHub Action that automatically creates machine-translated PRs of translation files. Supported file formats include:

  • .ini
  • .po
  • .restext
  • .resx
  • .xliff
  • .json

Usage

# 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:
    - '**.ini'       # INI-based, key value pair file format
    - '**.po'        # Portable Object file format
    - '**.restext'   # INI-based, key value pair file format
    - '**.resx'      # XML-based (resource) translation file format, .NET
    - '**.xliff'     # XML-based translation file format, version 2
    - '**.json'      # JSON-based, key value pair file format

# GitHub automatically creates a GITHUB_TOKEN secret to use in your workflow.
env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# 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 machine-translator to automatically translate resource files
      - name: Machine Translator
        id: translator
        uses: IEvangelist/[email protected]
        with:
          # The source locale (for example, 'en') used to create the glob pattern
          # for which resource (**/*.en.resx) files to use as input
          sourceLocale: 'en'
          # 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 }}
          # (Optional) Locales to translate to, otherwise all possible locales
          # are targeted. Requires double quotes.
          toLocales: '["es","fr","de"]'

      - name: create-pull-request
        uses: peter-evans/[email protected]
        if: ${{ steps.translator.outputs.has-new-translations }} == 'true'
        with:
          title: '${{ steps.translator.outputs.summary-title }}'
          commit-message: '${{ steps.translator.outputs.summary-details }}'

Inputs

Required Input name Example
Yes sourceLocale 'en'
Yes subscriptionKey 'c571d5d8xxxxxxxxxxxxxxxxxx56bac3'
Yes endpoint 'https://api.cognitive.microsofttranslator.com/'
No region 'canadacentral'
No toLocales '"es,de,fr"' or '["es","de","fr"]'

For more information, see GitHub Action using inputs.

Outputs

Input name Description
has-new-translations A boolean value indicating whether or not new translations have been generated.
summary-title A general summary title of the translations when they occur. Ideal for PR titles.
summary-details A detailed summary, formatted in Markdown. Ideal for PR message.

For more information, see GitHub Action outputs.

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

vs-savelich
vs-savelich

๐Ÿ’ป โš ๏ธ
Yevgen Nykytenko
Yevgen Nykytenko

๐Ÿ›
Peter Rekdal Khan-Sunde
Peter Rekdal Khan-Sunde

๐Ÿ›
Tim Heuer
Tim Heuer

๐Ÿ› ๐Ÿค” ๐Ÿ‘€
Tibor Tompa
Tibor Tompa

๐Ÿค”
Matteo
Matteo

๐Ÿ’ป โš ๏ธ

This project follows the all-contributors specification. Contributions of any kind welcome!

resource-translator's People

Contributors

allcontributors[bot] avatar dependabot[bot] avatar franklin89 avatar github-actions[bot] avatar ievangelist avatar vs-savelich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

resource-translator's Issues

BUG: Resulting translation files not correct

After upgrading to 2.0.2 the files coming back are not correct. Consider this:
timheuer/tacticview@0c7c193#diff-a8585a8435a28fbd36e66f9b21a54f23c255394e03998cd1bedd5d197e998dbc

This is most definitely not French (it is Finnish). And the German (de) one came back english. It's almost as if the first batch is 'off' a bit. The fr and a few files after that are all still Finnish.

In my debugging I'm pretty sure this:
https://github.com/IEvangelist/resource-translator/blob/main/src/api.ts#L51
needs to be batchedLocales instead of batchCount.

But I can't figure out why then it is only getting the last request -- it's definitely issuing an API call, but the resulting translations merged are only the last call.

Getting error 'The server rejected the request because the client has exceeded request limits.'

Hi,

We're getting this error when running. I had thought the action would only use the changed resources, but it's attempting to do the whole of all our files (we have 6 files for our convenience of finding things). It's managing to translate 19 batches of the first file before hitting this error, translating to 3 different languages. We're using the latest version of the action (2.1.7). It then continues to try and do the rest of the files but we've already exceeded our limits.

So, firstly, why is it trying to do the whole file instead of just the changes? Secondly, Azure aren't terribly helpful from what i've seen on the list of errors. Is this something that could pass in a matter of minutes? Could we add the ability to slow down to not hit the limit? Is this a daily or hourly limit?

The whole run time is just over a minute. I'd have no problem if i could set a variable to build in a slow down if that's what it takes!

Thanks

Julie

Translated only the diff elements

Maybe a tall task, but given how the Azure service works (word count), you will be over-translating after the first run. Consider only somehow translating the diff/change.

I realize this is a bigger ask as you're basically just translating all of them and emitting files.

Do not translate specific JSON keys

Hey there,

It would be awesome if you could include the option to specify an array of JSON keys whose values wouldn't be translated.

Azure Translator supports marking certain parts of the origin doc not to be translated, unfortunately that only works for HTML, and not for JSON.

Thanks!

set-output command is deprecated and will be disabled soon

Hi, GitHub Actions shows this warning.

Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Consider using request

const endpoint = 'https://api.cognitive.microsofttranslator.com';
const key = 'c57xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxac3';
const region = 'canadacentral';

function translateText() {
    let options = {
        method: 'POST',
        baseUrl: endpoint,
        url: 'translate',
        qs: {
          'api-version': '3.0',
          'to': ['de', 'it']
        },
        headers: {
          'Ocp-Apim-Subscription-Key': subscriptionKey,
          'Ocp-Apim-Subscription-Region': region,
          'Content-type': 'application/json'
        },
        body: [{
              'text': 'Hello World!'
        }],
        json: true,
    };

    request(options, function(err, res, body){
        console.log(JSON.stringify(body, null, 4));
    });
};

// Call the function to translate text.
translateText();

Stop pull request if not needed

Just to avoid unnecessary work, set an output from the translator action maybe (has_new_translations) and look for that as a conditional before the pull request and if not needed, then don't even bother checking.

Consider changing baseResourceGlob

Due to an issue how resources are actually looked up in .NET -- if you want to use your base type code-generated static class (old school .NET way -- but you still can) then you're base resource is .resx (no locale) as it is the fallback.

The code:

`**/*.${(getInput('sourceLocale') || 'en')}.resx`,
assumes to map sourceLocale to the file name and make that the lookup. I had thought sourceLocale just feeds into the API call but not hard-coding the path lookup.

Recommend changing this to be perhaps something different.

Error - The maximum request size has been exceeded.

We are in the process of using Azure Cognitive Services for translating a rather large enterprise application. When attempting to translate our resource files to multiple languages the following error is raised. The configured tier in Azure is S0. The error message appears to be triggered on longer sentences in our resx files. It's impossible with the current error message to identify which resource file and key that is causing the problem.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.