Skip to content

Commit

Permalink
Updated Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Globalfun32y439y54 authored Dec 18, 2024
1 parent 005523e commit 8590d4c
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 6 deletions.
169 changes: 169 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Badge Creator Usage Examples

- [Basic Config](#basic-config)
- [Translations export options configuration](#translations-export-options-configuration)
- [Triggers](#triggers)
- [Cron schedule](#cron-schedule)
- [Manually](#manually)
- [When a localization file is updated in the specified branch](#when-a-localization-file-is-updated-in-the-specified-branch)

---

### Basic Config

```yaml
name: Crowdin Action

on:
push:
branches: [ main ]

permissions:
contents: write
pull-requests: write

jobs:
crowdin:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Synchronize with Crowdin
uses: crowdin/github-action@v2
with:
upload_sources: true
upload_translations: true
download_translations: true
localization_branch_name: l10n_crowdin_translations

create_pull_request: true
pull_request_title: 'New Crowdin translations'
pull_request_body: 'New Crowdin pull request with translations'
pull_request_base_branch_name: 'main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
```
### Translations export options configuration
```yaml
name: Crowdin Action

on:
push:
branches: [ main ]

jobs:
crowdin:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Synchronize with Crowdin
uses: crowdin/github-action@v2
with:
upload_sources: true
upload_translations: false
download_translations: true

# Export options
skip_untranslated_strings: true
export_only_approved: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
```
## Triggers
### Cron schedule
```yaml
on:
schedule:
- cron: '0 */12 * * *' # Every 12 hours - https://crontab.guru/#0_*/12_*_*_*
```
### Manually
```yaml
on:
workflow_dispatch:
```
### When a localization file is updated in the specified branch
```yaml
on:
push:
paths:
- 'src/locales/en.json'
branches: [ main ]
```
### When a new GitHub Release is published
```yaml
on:
release:
types: [published]
```
### Dealing with concurrency
```yaml
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
```
### Handling parallel runs
In case your action fails when a build is in progress (409 error code), you need to configure the workflow in a way to avoid parallel runs.
```yaml
strategy:
max-parallel: 1
```
[Read more](https://github.com/crowdin/github-action/wiki/Handling-parallel-runs)
## Outputs
### `pull_request_url`, `pull_request_number`

There is a possibility to get the URL or number of the created Pull Request. You can use it in the next steps of your workflow.

```yaml
# ...
- name: Crowdin
uses: crowdin/github-action@v2
id: crowdin-download
with:
download_translations: true
create_pull_request: true
env:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
- name: Enable auto-merge for the PR
if: steps.crowdin-download.outputs.pull_request_url
run: gh pr --repo $GITHUB_REPOSITORY merge ${{ steps.crowdin-download.outputs.pull_request_url }} --auto --merge
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Approve the PR
if: steps.crowdin-download.outputs.pull_request_url
run: gh pr --repo $GITHUB_REPOSITORY review ${{ steps.crowdin-download.outputs.pull_request_url }} --approve
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ A GitHub action to manage and synchronize localization resources with your Crowd

</div>

## Usage
# Usage

Set up a workflow in *.github/workflows/crowdin.yml* (or add a job to your existing workflows).

Read the [Configuring a workflow](https://help.github.com/en/articles/configuring-a-workflow) article for more details on creating and setting up GitHub workflows.

### Sample workflow
## Sample workflow

```yaml
name: Badge Creator
Expand Down Expand Up @@ -63,11 +63,35 @@ jobs:
Enter the `PROJECT_ID` and `TOKEN` secrets under the Repository settings -> Secrets and variables -> Actions > Repository secrets.

## Supported options
### Supported options

| Option | Description | Example value |
|----------------------------|----------------------------------------------------------------------------------------------------|------------------------------|
| `token` | Your Crowdin API token so it can get your translations | `${{ secrets.TOKEN }}` |
| `project_id` | You Crowdin Project ID so it can get the right translations | `${{ secrets.PROJECT_ID }}` |
| `output_path` | The path your .svg file is saved to | `./icon` |
| `language_rename_map` | So you rename the name of the translations in the .svg file | `{"German":"Deutsch","Spanish":"Español"}` |
| `toggledefault` | This allow you set add your default language into the .svg file | `false` (default) |
| `defaultlanguage` | This is the feild you add the progress and name of the default language | [Click Me](#defaultlanguage) |




### Default Language Example
```json
{
"name": "English",
"progress": 100,
"url": "https://crowdin.com/project/bettercanvas",
"color": "#2eccaa"
}
```

### Supported options for default language

| Option | Description | Example value |
|----------------------------|----------------------------------------------------------------------------------------------------|------------------------------|
| `name` | The name of the default language | `English` |
| `progress` | The total progress of the language (Dont add a % sign. It adds it for you) | `100` |
| `url` | The url to the language strings | `https://crowdin.com/project/bettercanvas` |
| `color` | This depends of the progress of your language (progress > 90 #2eccaa, progress > 50 #38f, progress > 0 #f6664c) | `English` |
13 changes: 11 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'badge-creator'
description: 'This action allows you to make a badge that shows the translation progress of your Crowdin project'
author: 'GlobalFun'
author: 'Globalfun32y439y54'

branding:
icon: 'bar-chart'
Expand All @@ -21,9 +21,18 @@ inputs:
required: false
default: '{}'
output_path:
description: Directory to save the generated files
description: 'Directory to save the generated files'
required: false
default: './'
toggledefault:
description: 'This allows you so show your default language'
required: false
default: 'false'
defaultlanguage:
description: 'JSON string to default language (e.g., { "name": "English", "progress": 100, "url": "https://crowdin.com/project/bettercanvas" }'
required: false
default: '{}'


outputs:
svg:
Expand Down
25 changes: 24 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,30 @@ function generateSVG(data) {
<g id="layer1">
`;

let yPosition = 20; // Starting Y-coordinate
let yPosition = 20;

if (core.getInput('toggledefalt') === true) {

let defaltlanguage;
try {
defaltlanguage = JSON.parse(core.getInput('defaltlanguage') || '{}');
} catch (err) {
console.error('Error parsing defaltlanguage input:', err.message);
defaltlanguage = {};
}

const { name, progress, url } = defaltlanguage

svgContent += `
<a xlink:href="${url}" xlink:title="${name}">
<text xml:space="preserve" x="238" y="${yPosition}" style="font-style:normal;font-weight:normal;font-size:11px;font-family:'Source Sans 3',sans-serif;fill:#808080;text-anchor:end;">${name}</text>
<text xml:space="preserve" x="408" y="${yPosition}" style="font-style:normal;font-weight:normal;font-size:11px;font-family:'Source Sans 3',sans-serif;fill:#808080">${progress}%</text>
<rect x="248" y="${yPosition - 6}" width="150" height="6" rx="2" style="fill:#2eccaa;fill-opacity:1;stroke:none"></rect>
</a>
`;

yPosition += 15;
}

data.languages.forEach(lang => {
const { name, progress, url } = lang;
Expand Down

0 comments on commit 8590d4c

Please sign in to comment.