Skip to content

Commit

Permalink
Merge pull request #144 from paulbalandan/revamp-testing
Browse files Browse the repository at this point in the history
Revamp testing for translations
  • Loading branch information
paulbalandan authored Nov 29, 2020
2 parents 3b1b56d + 50c3bc0 commit efe59f0
Show file tree
Hide file tree
Showing 52 changed files with 1,134 additions and 628 deletions.
78 changes: 78 additions & 0 deletions .github/scripts/continuous-integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env php
<?php

error_reporting(-1);
ini_set('display_errors', '1');

require __DIR__ . '/../../vendor/autoload.php';

use CodeIgniter\Language\AbstractTranslationTestCase;

$args = $_SERVER['argv'];

if (! isset($args[1]))
{
fwrite(STDERR, 'Changed files are not provided. Aborting...');
exit(1);
}

$files = $args[1];
unset($args);

$files = explode(' ', trim($files));

$stagedPhpFiles = [];

foreach ($files as $file)
{
if (substr($file, -4) === '.php')
{
$stagedPhpFiles[] = $file;
}
}

$locales = [];

foreach ($stagedPhpFiles as $file)
{
if (preg_match('/^Language\/(.*)\/.*\.php$/', $file, $matches))
{
$locales[] = $matches[1];
}
}

$locales = array_unique($locales);
$count = count($locales);

chdir(__DIR__ . '/../../');

if ($count === 0)
{
fwrite(STDOUT, 'No language files to test.');
exit(0);
}

if ($count === count(AbstractTranslationTestCase::$locales))
{
$return = 0;
fwrite(STDOUT, "Testing all language files in all locales.\n\n");
passthru('vendor/bin/phpunit --filter AllLocalesTranslationTest', $return);

exit($return);
}

$returns = 0;
$return = 0;

foreach ($locales as $locale)
{
$localeMap = array_flip(AbstractTranslationTestCase::$locales);
$class = preg_replace('/^CodeIgniter\\\\Language\\\\(.*)$/u', '$1', $localeMap[$locale]);

fwrite(STDOUT, 'Executing vendor/bin/phpunit --color=always --filter ' . $class . "\n\n");
passthru("vendor/bin/phpunit --color=always --filter {$class}", $return);

$returns += $return;
}

exit($returns ? 1 : 0);
72 changes: 72 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: build

on:
push:
branches:
- develop
paths:
- Language/**
- tests/Language/**
- .github/workflows/build.yml
pull_request:
branches:
- develop
paths:
- Language/**
- tests/Language/**
- .github/workflows/build.yml

jobs:

main:
name: Build [PHP ${{ matrix.php-versions }}]
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"

strategy:
fail-fast: false
matrix:
php-versions: ['7.3', '7.4']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer
extensions: intl, mbstring, xdebug
coverage: xdebug

- name: Validate composer.json
run: composer validate --strict

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Create composer cache directory
run: mkdir -p ${{ steps.composer-cache.outputs.dir }}

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Setup Composer's GitHub OAuth access to prevent rate limiting
run: composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer update --ansi --no-scripts --no-interaction

- name: Get changed files
id: files
uses: jitterbit/get-changed-files@v1

- name: Run Translations Test Suite
run: |
php .github/scripts/continuous-integration "${{ steps.files.outputs.all }}"
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,5 @@ nb-configuration.xml
# Visual Studio Code
.vscode/

/results/
/phpunit*.xml
/.phpunit.*.cache
phpunit.xml
.phpunit.cache/
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

84 changes: 56 additions & 28 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Contributing to the CodeIgniter 4 translations
# Contributing to the CodeIgniter 4 Translations

We welcome contributions, to the *develop* branch,
to add new translations or update existing ones.
We welcome contributions, to the **develop** branch, to add new translations or update existing ones.

If you have a translation or correction, please fork the repository, clone it
locally, and then create a new branch (from develop)
for each set of related changes or for
a complete language pack. Once your branch is complete, *then* create a pull
locally, and then create a new branch (from `develop`) for each set of related changes
or for a complete language pack. Once your branch is complete, create a pull
request to merge it into the develop branch of this repository.

If you are contributing a variant of a main locale (e.g. "en-CA"), you
only need to provide those translations that differ from it.

Each translation set would go inside a folder named following the two-letter ISO-639-1 language code.
Localization variants would have folders named with the two-letter ISO 639-1 language code in lowercase,
followed by the two-letter ISO 3166 country code capitalized,
and with the two parts separated by a hyphen.
An example would be "en" for English, and "en-US" for the variations appropriate to the United States.
Localization variants would have folders named with the two-letter ISO 639-1 language code in lowercase,
followed by the two-letter ISO 3166 country code capitalized,
and with the two parts separated by a hyphen. An example would be "en" for English, and "en-US" for the
variations appropriate to the United States.

Pull requests to the repository will only be considered if they come from
the maintainer for any translations in the request, or if the maintainer
Expand All @@ -31,32 +29,62 @@ PR conversations should be conducted in English, thanks.
We would like to see GPG-signed commits for contributions,
and we have unit testing to help determine if your translations are complete.

The unit testing looks for translation sets missing language settings that
are in the framework repository's `app/Language/en folder`, and for settings
The unit testing looks for translation sets' missing language settings that
are in the framework repository's `system/Language/en/ folder`, and for settings
in a translation set that are not in that folder.

The unit testing is expected to fail, unless all translation sets are totally
in synch with the framework's. Look for your language set in the travis-ci
details for your pull request.
Unit tests for a specific locale should pass. Failures would be thrown to clearly
show which files are missing or extra or which language strings are missing or extra.

For instance, a travis-ci excerpt showing that the `fa` translation is missing
a specific set of messages:
For instance, a test error showing that the `de` translation has extra files not found in the framework:

12) CodeIgniter\Language\TranslationsTest::testExtraFiles with data set "fa" ('fa')
fa has extra files: Filter.php
1) CodeIgniter\Language\GermanTranslationTest::testAllTranslatedLanguageFilesAreConfigured with data set "de" ('de')
Failed asserting that translated language file "Seed.php" in "de" locale is configured in the main repository.
Failed asserting that an array is empty.

This was caused by `Filters.php` incorrectly named `Filter,php`.
Another example showing missing files in the `de` translation set:

An example showing missing keys for the `sk` translation set:
2) CodeIgniter\Language\GermanTranslationTest::testAllConfiguredLanguageFilesAreTranslated with data set "de" ('de')
Failed asserting that language file "CLI.php" in the main repository is translated in "de" locale.
Failed asserting that an array is empty.

10) CodeIgniter\Language\TranslationsTest::testMissingFiles with data set "sk" ('sk')
sk is missing: RESTful.php Email.php Encryption.php
An example showing missing keys for the `de` translation set:

These would be caused by message sets added to the framework but not here.
3) CodeIgniter\Language\GermanTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "de" ('de')
Failed asserting that the language keys "CLI.altCommandPlural", "CLI.altCommandSingular", "CLI.generateClassName", "CLI.generateFileError", "CLI.generateFileExists", "CLI.generateFileSuccess", "CLI.generateParentClass", "CLI.namespaceNotDefined", "Database.emptyDataset", "Database.emptyPrimaryKey", "Email.sent", "Fabricator.createFailed", "Format.invalidFormatter", "Format.invalidMime", "HTTP.invalidSameSiteSetting", "Migrations.batch", "Migrations.group", "Migrations.missingTable", "Migrations.nameSeeder", "Migrations.namespace", "Session.invalidSameSiteSetting", "Validation.not_in_list" in the main repository are included for translation in "de" locale.
Failed asserting that an array is empty.

And an example showing extra keys for the `it` translation set:
Lastly, an example showing extra keys for the `de` translation set:

33) CodeIgniter\Language\TranslationsTest::testExtraKeys with data set "it" ('it')
it has extra keys: Files.invalidFilename Files.cannotCopy Images.unsupportedImagecreate
4) CodeIgniter\Language\GermanTranslationTest::testAllIncludedLanguageKeysAreConfigured with data set "de" ('de')
Failed asserting that the translated language keys "Migrations.badCreateName", "Migrations.writeError" in "de" locale are configured in the main repository.
Failed asserting that an array is empty.

This would be caused by messages removed or renamed in the framework, and not reflected here.
The failure messages are fully descriptive of what went wrong in the translation process.

## Extending Unit Tests

Each language locale in this repository has a corresponding test class located in `tests/Language/` folder.
These test classes test individually the language sets for its completeness and precision. However, the test
class `CodeIgniter\Language\AllLocalesTranslationTest` tests **ALL** locales at once. This is used for a
full-blown testing of all language sets.

When adding a new locale for translation, the following steps should be followed strictly:

1. Make sure the language files to be translated are found in the framework's main repository.
2. Create a new test class in `tests/Language` folder. For example, the new locale is Canadian French
(fr-CA), then a test class named `CanadianFrenchTranslationTest` will be created. The pattern for naming is
the full name of the new locale followed by `TranslationTest`.
3. This new test class should be extending `CodeIgniter\Language\AbstractTranslationTestCase` and be marked
as a final class. This would not contain any new methods or properties as its sole purpose is to extend
`AbstractTranslationTestCase` for testing the specific locale.
4. In the static `$locales` array of `AbstractTranslationTestCase` this new class should be added. The name
of the new class would be the key and its corresponding locale would be the value. The `$locales` array
should be sorted on the basis of values.
5. Add the details of new locale in [README](README.rst). If the details is originally in
the [MISSING](MISSING.rst), remove the details from there.
6. After that, run the unit tests for your new locale:

vendor/bin/phpunit --filter CanadianFrenchTranslationTest

7. When tests all pass, go create a pull request!
10 changes: 1 addition & 9 deletions MISSING.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
***************************
Missing/needed translations
Missing/Needed translations
***************************

The following languages have translations for CodeIgniter 3, but not yet for CodeIgniter 4:
Expand All @@ -13,29 +13,21 @@ bn Bengali kabircse Kabir Hossain
bg Bulgarian ivantcholakov Ivan Tcholakov
ca Catalan Ignasimg Ignasi Molsosa
hr Croatian PaleRider981 Mario Ljubicic
cs Czech Ruplahlava Štěpán Postránecký
da Danish janhansson* Jan Hansson
nl dutch pkrul Pieter Krul
fil filipino dzerium Edzer Josh V. Padilla ... See note below
gu Gujarati sajid19991 Sajid Mathupotra
hi Hindi shindesushilkumar Sushilkumar Shinde
hu Hungarian orionstar László Bóra
ja Japanese ? ?
km Khmer Chanthoeun Chanthoeun Kim
fa Persian MSDehghan Mohammad Sadegh
ro Romanian CodefishRo Cristian Robert Chiribuc
sr Serbian novakurosevic Novak Urosevic ???
sl Slovenian andrejflorjancic Andrej Florjančič
sv Swedish peterdenk Peter Denk
ta Tamil karthik-code Karthikeyan
th Thai ? ?
uk Ukranian flybot Sergiy Kosiy
ur Urdu codeonion Muhammad Ali
vi Vietnamese tinhphaistc Trần Xuân Sâm ???
======== ==================== ================= =========================

Notes:

- Filipino has a 639-2 code, while tl (Tagalog) is the 639-1 code; which to use?


14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ Translations for CodeIgniter 4 System Messages
##############################################

This project contains translations for CodeIgniter 4
localization, eg. **system/Language/en**.
localization, e.g. **system/Language/en/**.

Copy the folder(s) for the locales you are interested in,
from inside the **Language** folder of this project to your
**application/Language** folder.
**app/Language/** folder.

You may then use the CodeIgniter Language class to reference the translations
directly ... see the `User Guide <https://codeigniter4.github.io/CodeIgniter4/outgoing/localization.html>`_.

Localization in CodeIgniter 4 follows the `ISO 639-1 conventions <https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes>`_.
Each translation set would go inside a folder named following the two-letter language code from here.

Localization variants are provided for, as folders named with the two-letter ISO 639-1 language code in lowercase,
followed by the two-letter `ISO 3166 country code <https://en.wikipedia.org/wiki/ISO_3166-1>`_ capitalized,
and with the two parts separated by a hyphen.
Localization variants are provided for, as folders named with the two-letter ISO 639-1 language code in lowercase,
followed by the two-letter `ISO 3166 country code <https://en.wikipedia.org/wiki/ISO_3166-1>`_ capitalized,
and with the two parts separated by a hyphen.
An example would be "en" for English, and "en-US" for the variations appropriate to the United States.

**********************
Expand Down Expand Up @@ -47,7 +47,7 @@ ko Korean 4.0.0* Timothy-Y-H-Lee Timothy-Y-H-Lee
lt Lithuanian 4.0.0* dgvirtual Donatas Glodenis
lv Latvian 4.0.0* davislasis Dāvis Lasis
ml Malayalam 4.0.0 rakheshthayyur Rakhesh Thayyur
nl Dutch 4.0.0 JohanSmolders JohanSmolders
nl Dutch 4.0.0 JohanSmolders JohanSmolders
no Norwegian 4.0.0 LA3QMA Kai Günter Brandt
pl Polish 4.0.0 DEVELPL Maciej Jasiewicz
pt Portugese 4.0.0 rbm0407 Rodrigo Borges
Expand All @@ -72,5 +72,3 @@ License
*******

These translations are licensed under the `MIT license <LICENSE>`_.

`Jim Parry <[email protected]>`_
Loading

0 comments on commit efe59f0

Please sign in to comment.