Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- name: Check out repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -57,10 +58,10 @@ jobs:
- name: Run PHP linter (php-cs-fixer)
run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer --diff --dry-run -v fix

- name: Atoum tests
- name: Unit tests
run: |
cp app/config/config.ini-ghactions app/config/config.ini
vendor/atoum/atoum/bin/atoum -d tests/units/ --use-light-report
php ./vendor/bin/phpunit

- name: Functional tests (API, pages)
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
.php-cs-fixer.cache
.phpunit.result.cache
*.pyc
app/config/config.ini
app/config/sources/*.json
Expand All @@ -14,6 +15,7 @@ composer.phar
logs/*.log
logs/github_log.txt
python-venv
tests/**/*.cache
vendor
web/data.tar.gz
web/download/.htaccess
Expand Down
4 changes: 4 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
],
'encoding' => true,
'full_opening_tag' => true,
'method_argument_space' => [
'on_multiline' => 'ignore',
'keep_multiple_spaces_after_comma' => false,
],
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down
4 changes: 2 additions & 2 deletions app/classes/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static function getRepositoryLocales($repository, $ignored = [])
$file_name = APP_SOURCES . "{$repository}.txt";
$supported_locales = [];
if (file_exists($file_name)) {
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}

// Make sure that the reference locale is included
Expand All @@ -245,7 +245,7 @@ public static function getAllLocales()
$file_name = APP_SOURCES . 'all_projects.txt';
$supported_locales = [];
if (file_exists($file_name)) {
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
sort($supported_locales);

Expand Down
2 changes: 1 addition & 1 deletion app/classes/Transvision/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,6 @@ public static function levenshteinQuality($string1, $string2)
mb_strlen($string2, 'UTF-8'),
]);

return (float) (1 - self::levenshteinUTF8($string1, $string2) / $length) * 100;
return (float) round((1 - self::levenshteinUTF8($string1, $string2) / $length) * 100, 5);
}
}
26 changes: 16 additions & 10 deletions app/classes/Transvision/TMX.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ class TMX
/**
* Generate a TMX file from a data source
*
* @param array $strings All the strings the user picked
* @param string $target_lang Locale picked from which we get translations
* @param string $source_lang Source locale
* @param array $strings All the strings the user picked
* @param string $target_lang Locale picked from which we get translations
* @param string $source_lang Source locale
* @param string|null $time Optional time string (in a valid date format) to use for creationdate; if not provided, date('c') is used.
*
* @return mixed string that contains a TMX in xml format, False otherwise
*/
public static function create($strings, $target_lang, $source_lang)
public static function create($strings, $target_lang, $source_lang, $time = null)
{
if ($strings[$target_lang] && $strings[$source_lang]) {
$creationDate = $time ?? date('c');

$content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
. '<tmx version="1.4">' . "\n"
. '<header o-tmf="plain text" o-encoding="UTF8" adminlang="en"'
. ' creationdate="' . date('c') . '" creationtoolversion="0.1" creationtool="Transvision"'
. ' creationdate="' . $creationDate . '" creationtoolversion="0.1" creationtool="Transvision"'
. ' srclang="' . $source_lang . '" segtype="sentence" datatype="plaintext">' . "\n"
. '</header>' . "\n"
. '<body>' . "\n";
Expand Down Expand Up @@ -56,21 +59,24 @@ public static function create($strings, $target_lang, $source_lang)
/**
* Generate a TMX file from a data source with the format of OmegaT
*
* @param array $strings All the strings the user picked
* @param string $target_lang Locale picked from which we get translations
* @param string $source_lang Source locale
* @param array $strings All the strings the user picked
* @param string $target_lang Locale picked from which we get translations
* @param string $source_lang Source locale
* @param string|null $time Optional time string (in a valid date format) to use for creationdate; if not provided, date('c') is used.
*
* @return mixed string that contains a TMX in xml format, False otherwise
*/
public static function createOmegat($strings, $target_lang, $source_lang)
public static function createOmegat($strings, $target_lang, $source_lang, $time = null)
{
if ($strings[$target_lang] && $strings[$source_lang]) {
$creationDate = $time ?? date('c');

$content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
. '<!DOCTYPE tmx SYSTEM "tmx11.dtd">' . "\n"
. '<tmx version="1.1">' . "\n"
. '<header creationtool="Transvision" o-tmf="OmegaT TMX" o-encoding="UTF8"'
. ' adminlang="EN-US" datatype="plaintext" creationtoolversion="0.1" segtype="paragraph"'
. ' creationdate="' . date('c') . '" srclang="' . $source_lang . '">'
. ' creationdate="' . $creationDate . '" srclang="' . $source_lang . '">'
. '</header>' . "\n"
. '<body>' . "\n";

Expand Down
36 changes: 18 additions & 18 deletions app/inc/constants.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php

// Constants for the project
define('DATA_ROOT', realpath($server_config['root']) . '/');
define('HG', realpath($server_config['local_hg']) . '/');
define('GIT', realpath($server_config['local_git']) . '/');
define('TMX', DATA_ROOT . 'TMX/');
define('INSTALL_ROOT', realpath($server_config['install']) . '/');
define('APP_SOURCES', realpath($server_config['config']) . '/sources/');
define('WEB_ROOT', INSTALL_ROOT . 'web/');
define('APP_ROOT', INSTALL_ROOT . 'app/');
define('INC', APP_ROOT . 'inc/');
define('VIEWS', APP_ROOT . 'views/');
define('MODELS', APP_ROOT . 'models/');
define('CONTROLLERS', APP_ROOT . 'controllers/');
define('DATA_ROOT', realpath($server_config['root']) . '/');
define('HG', realpath($server_config['local_hg']) . '/');
define('GIT', realpath($server_config['local_git']) . '/');
define('TMX', DATA_ROOT . 'TMX/');
define('INSTALL_ROOT', realpath($server_config['install']) . '/');
define('APP_SOURCES', realpath($server_config['config']) . '/sources/');
define('WEB_ROOT', INSTALL_ROOT . 'web/');
define('APP_ROOT', INSTALL_ROOT . 'app/');
define('INC', APP_ROOT . 'inc/');
define('VIEWS', APP_ROOT . 'views/');
define('MODELS', APP_ROOT . 'models/');
define('CONTROLLERS', APP_ROOT . 'controllers/');
define('CACHE_ENABLED', isset($_GET['nocache']) ? false : true);
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');

if (php_sapi_name() != 'cli') {
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
}

/*
Expand All @@ -39,14 +39,14 @@
define('BETA_VERSION', $beta_version);

if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
} else {
// 05h20 cache (because we extract data every 6h and extraction lasts 25mn)
define('CACHE_TIME', 19200);
define('CACHE_TIME', 19200);
}

// Special modes for the app
define('DEBUG', BETA_VERSION || isset($_GET['debug']));
define('DEBUG', BETA_VERSION || isset($_GET['debug']));
define('LOCAL_DEV', isset($server_config['dev']) && $server_config['dev']);

// Set perf_check=true in config.ini to log page time generation and memory used while in DEBUG mode
Expand Down
2 changes: 1 addition & 1 deletion app/views/credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<li>Bash for installation scripts and cron jobs</li>
<li>Python for extracting strings (compare-locales)</li>
<li><a href="https://getcomposer.org/">Composer</a>, a dependency manager for PHP projects</li>
<li><a href="https://www.atoum.org/">Atoum</a>, a unit testing framework for PHP</li>
<li><a href="https://www.phpunit.de/">PHPUnit</a>, a unit testing framework for PHP</li>
<li><a href="https://www.jquery.com/">jQuery</a>, a JavaScript library</li>
</ul>

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
},

"require-dev": {
"atoum/atoum" : "~4.2",
"symfony/var-dumper": "~6.4",
"friendsofphp/php-cs-fixer": "~3.64",
"pchevrel/verif": "0.4"
"friendsofphp/php-cs-fixer": "~3.75",
"pchevrel/verif": "0.4",
"phpunit/phpunit": "^10 || ^12"
},

"autoload": {
Expand Down
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/units/bootstrap.php"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true">
<php>
<!-- Report every error, warning, and notice -->
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="1"/>
</php>
<testsuites>
<testsuite name="Unit Tests">
<directory>tests/units</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ case "$1" in
SERVER="0.0.0.0:8082"
;;
-tests)
php ./vendor/atoum/atoum/bin/atoum -d tests/units/ --use-light-report
php ./vendor/bin/phpunit
php ./tests/functional/api.php
php ./tests/functional/pages.php
vendor/bin/php-cs-fixer --diff --dry-run -v fix
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/includes/init.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('INSTALL_ROOT', realpath(__DIR__ . '/../../../') . '/');
define('INSTALL_ROOT', realpath(__DIR__ . '/../../../') . '/');

// We always work with UTF8 encoding
mb_internal_encoding('UTF-8');
Expand Down
20 changes: 0 additions & 20 deletions tests/units/ChooseLocale.php

This file was deleted.

Loading