A hacky python script that handles some of the menial tasks regarding translations for my Lua projects.
It has two functionalities and a bunch of requirements, and the function keyword is the only argument it takes.
This function will do the following:
- It will read a specific issue
- Which issue is defined by two environment variables:
GITHUB_REPOSITORY
, expected format:<repo_owner>/<repo_name>
, e.g.p3lim/lua-translations
GITHUB_EVENT_ISSUE
, expected format:<issue_id>
, e.g.10
- It will parse the issue body as expected from the template created by the "extract" function
- From this it will find the language submitted in the issue, and each string with their translations
- It will generate translation files in Lua at
locale/<lang>.lua
- The format of each string is
L["original english string"] = "translated string"
- It will define a header using World of Warcraft Lua AddOn namespace, specific to a library I use
This is really specific to a certain usecase (mine), so if you want to use this for yourself it's recommended to fork the project and adjust these templates yourself (or use my library).
Using it in a GitHub workflow with an action to auto-create pull requests (or auto-commit directly) is recommended, see below for an example.
This function will do the following:
- It will read all Lua files in the working directory
- It will look for any localization strings
- unless they have
bot-ignore
anywhere on the line
- It will update a GitHub issue template with the strings, to act as a form for people to submit translations
It has some very specific requirements:
- The strings will be matched using a regex pattern:
L\[["'](.*)["']\]
- Example Lua object:
L["This is the string"]
- Example output string:
This is the string
- It expects a GitHub issue label named
translation
to exist - It auto-assigns the issue from the issue form to the GitHub repository owner
Using it in a GitHub workflow with an action to auto-create pull requests (or auto-commit directly) is recommended.
These are two example workflows using both functions of this project:
name: Update translation issue template
on:
push:
branches:
- master
tags-ignore:
- '**'
jobs:
template:
runs-on: ubuntu-latest
steps:
- name: Clone project
uses: actions/checkout@v4
- name: Update issue template
uses: p3lim/lua-translations@master # or pin to sha
with:
action: template
- name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
title: Update translation issue template
body:
commit-message: Update translation issue template
branch: translation-issue-template
delete-branch: true
name: Create pull request from translation form
on:
issues:
types: [labeled]
env:
GITHUB_EVENT_ISSUE: ${{ github.event.issue.number }}
jobs:
extract:
if: ${{ github.event.label.name == 'translation' }}
runs-on: ubuntu-latest
steps:
- name: Clone project
uses: actions/checkout@v4
- name: Extract translations
uses: p3lim/lua-translations@master # or pin to sha
with:
action: extract
id: extract
- name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
title: Update ${{ steps.extract.outputs.lang }} translation
body:
commit-message: |
Update ${{ steps.extract.outputs.lang }} translation
Fixes #${{ github.event.issue.number }}
branch: update-translation-${{ github.event.issue.number }}
delete-branch: true