Skip to content

Commit

Permalink
Merge pull request #324 from translate-tools/323-not-set-message-in-l…
Browse files Browse the repository at this point in the history
…ocales-fix-and-setup-linting

Not set message in locales. FIx and setup linting
  • Loading branch information
vitonsky committed Apr 25, 2023
2 parents 7aee83d + 4b03540 commit 65646d3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
Expand All @@ -20,6 +15,8 @@ on:
schedule:
- cron: '43 4 * * 6'

workflow_dispatch:

jobs:
tests:
name: Tests
Expand All @@ -37,6 +34,32 @@ jobs:
- name: Run tests
run: npm test

# TODO: get known how to specify glob paths like `thirdparty/bergamot/{*,**/*}` to depends on all files
# Docs: https://github.com/actions/cache
- name: Cache bergamot
id: cache-bergamot
uses: actions/cache@v3
with:
path: thirdparty/bergamot/build/*
# TODO: add month to key, to deprecate old cache `date -u +'%m.%G'`
# Try this approach: https://stackoverflow.com/questions/57968497/how-do-i-set-an-env-var-with-a-bash-expression-in-github-actions
# If it will works fine, we can try use directory git hash as key
# cache strategy https://github.com/actions/cache/blob/main/caching-strategies.md#updating-cache-for-any-change-in-the-dependencies
key: ${{ runner.os }}-cache-bergamot-${{ hashFiles('thirdparty/bergamot/*', 'thirdparty/bergamot/src/**/*.ts') }}

- name: Compile third party with docker
if: steps.cache-bergamot.outputs.cache-hit != 'true'
working-directory: './thirdparty/bergamot'
run: |
make dockerBuildContainer
make dockerRunContainer
# We build with docker, because Github actions cannot to make correct build due to deps (puppeteer to convert images, etc)
- name: Build app with docker and lint build
run: |
make dockerBuildContainer
make dockerRunContainer
analyze:
name: Analyze
runs-on: ubuntu-latest
Expand Down
47 changes: 41 additions & 6 deletions scripts/locales/utils/syncLocalizations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { writeFileSync } = require('fs');
const { isEqual } = require('lodash');

const {
getLocaleFilenames,
Expand Down Expand Up @@ -151,17 +152,51 @@ const syncLocalizationsFilesWithSource = async () => {
const sourceLocalization = getSourceLocale();
const localizationFiles = getLocaleFilenames();

const recheckAttempts = 5;
const filesWithChanges = [];

const changedMessages = getChangedLocaleMessageNames(sourceLocalization);
for (const filePath of localizationFiles) {
// Skip source file
if (filePath === sourceLocalization.filename) continue;

const targetLocalization = getLocaleObject(filePath);
await syncLocalizationsMessagesWithSource(
sourceLocalization,
targetLocalization,
changedMessages,
);
let latestObject = null;
for (
let recheckAttemptNumber = 0;
recheckAttemptNumber <= recheckAttempts;
recheckAttemptNumber++
) {
const targetLocalization = getLocaleObject(filePath);
await syncLocalizationsMessagesWithSource(
sourceLocalization,
targetLocalization,
changedMessages,
);

const actualLocalizationData = getLocaleObject(filePath).json;

// Check changes. If no have changes, then we successful translate all messages
if (latestObject !== null && recheckAttemptNumber > 0) {
const isObjectHaveChanges = !isEqual(
latestObject,
actualLocalizationData,
);

if (!isObjectHaveChanges) break;

// Add file to array to report
if (recheckAttemptNumber >= recheckAttempts) {
filesWithChanges.push(filePath);
}
}

latestObject = actualLocalizationData;
}
}

if (filesWithChanges.length > 0) {
console.error('Files that exceed attempts to fix changes', filesWithChanges);
throw new Error('Some files been not translated correctly');
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/_locales/cs/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"message": "Překlady stránek a textů, slovník, historie, offline a vlastní překladatelé"
},
"ext_name": {
"zprava": "Linguist - překladatel webových stránek"
"message": "Lingvista - překladatel webových stránek"
},
"history_control_selectEntry": {
"message": "Vybrat položku"
Expand Down

0 comments on commit 65646d3

Please sign in to comment.