From fc463bc0952695ce7bdcd5d937cf3182e27df9d4 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Wed, 31 May 2023 10:31:27 +0300
Subject: [PATCH 01/10] Added Symfony translation component
---
composer.json | 6 +++++-
src/controller/Controller.php | 4 ++--
src/controller/WebController.php | 23 ++++++++++++++++++++++-
src/index.php | 1 +
src/view/base-template.twig | 10 +++++-----
5 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/composer.json b/composer.json
index 5923ba803..a92884363 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,11 @@
"ext-intl": "*",
"ext-mbstring": "*",
"ext-xsl": "*",
- "monolog/monolog": "1.27.*"
+ "monolog/monolog": "1.27.*",
+ "symfony/translation": "6.0.*",
+ "symfony/translation-contracts": "3.0.*",
+ "symfony/twig-bundle": "6.0.*",
+ "symfony/config": "6.0.*"
},
"require-dev": {
"phpunit/phpunit": "9.5.*",
diff --git a/src/controller/Controller.php b/src/controller/Controller.php
index 07e52063d..d9fed7ad7 100644
--- a/src/controller/Controller.php
+++ b/src/controller/Controller.php
@@ -42,8 +42,8 @@ public function __construct($model)
foreach ($this->model->getConfig()->getLanguages() as $langcode => $locale) {
$this->languages[$langcode] = array('locale' => $locale);
$this->setLanguageProperties($langcode);
- $this->languages[$langcode]['name'] = gettext('in_this_language');
- $this->languages[$langcode]['lemma'] = Punic\Language::getName($langcode, $langcode);
+ //$this->languages[$langcode]['name'] = gettext('in_this_language');
+ //$this->languages[$langcode]['lemma'] = Punic\Language::getName($langcode, $langcode);
}
}
diff --git a/src/controller/WebController.php b/src/controller/WebController.php
index 2fdc8cf78..76fc1c7a0 100644
--- a/src/controller/WebController.php
+++ b/src/controller/WebController.php
@@ -4,7 +4,9 @@
* Importing the dependencies.
*/
use Punic\Language;
-
+use Symfony\Component\Translation\Translator;
+use Symfony\Component\Translation\Loader\PoFileLoader;
+use Symfony\Bridge\Twig\Extension\TranslationExtension;
/**
* WebController is an extension of the Controller that handles all
* the requests originating from the view of the website.
@@ -64,6 +66,13 @@ public function __construct($model)
});
$this->twig->addFilter($langFilter);
+ foreach( $this->languages as $langcode => $value ) {
+ $translator = new Translator($langcode);
+ $translator->addLoader('po', new PoFileLoader());
+ $translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $langcode . '.po', $langcode);
+ $this->languages[$langcode]['name'] = $translator->trans('in_this_language');
+ }
+
// create the honeypot
$this->honeypot = new \Honeypot();
if (!$this->model->getConfig()->getHoneypotEnabled()) {
@@ -72,6 +81,18 @@ public function __construct($model)
$this->twig->addGlobal('honeypot', $this->honeypot);
}
+ /**
+ * Creates and registers the translation extension and loads translation file.
+ * @param string $lang two character language code
+ */
+ public function addTranslations($lang)
+ {
+ $translator = new Translator($lang);
+ $translator->addLoader('po', new PoFileLoader());
+ $translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $lang . '.po', $lang);
+ $this->twig->addExtension(new TranslationExtension($translator));
+ }
+
/**
* Guess the language of the user. Return a language string that is one
* of the supported languages defined in the $LANGUAGES setting, e.g. "fi".
diff --git a/src/index.php b/src/index.php
index d00b70e64..b11d8b2b2 100644
--- a/src/index.php
+++ b/src/index.php
@@ -31,6 +31,7 @@
} else {
if (array_key_exists($parts[1], $config->getLanguages())) { // global pages
$request->setLang($parts[1]);
+ $controller->addTranslations($parts[1]);
$content_lang = $request->getQueryParam('clang');
$request->setContentLang($content_lang);
($parts[2] == 'about' || $parts[2] == 'feedback' || $parts[2] == 'search') ? $request->setPage($parts[2]) : $request->setPage('');
diff --git a/src/view/base-template.twig b/src/view/base-template.twig
index a1bd29bef..0857af599 100644
--- a/src/view/base-template.twig
+++ b/src/view/base-template.twig
@@ -29,24 +29,24 @@
-
- Vocabularies-nav
+ {{ "Vocabularies" | trans }}
-
- About page
+ {{ "About" | trans }}
-
- Feedback
+ {{ "Feedback" | trans }}
{% if languages|length > 1 %}
{% for langcode, langdata in languages %}
{% if request.lang != langcode %}
-
- {{langdata.name}}
+ {{ langdata.name }}
{% endif %}
{% endfor %}
@@ -80,7 +80,7 @@
-
Contact
+
{{ "Contact us!" | trans }}
Yhteystiedot?
From 8b92d1621e17da68e47c79f493866816a01aaff1 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Wed, 31 May 2023 16:16:20 +0300
Subject: [PATCH 02/10] Translation files are added only once for each language
---
src/controller/Controller.php | 2 --
src/controller/WebController.php | 22 ++++++++++++----------
src/index.php | 2 +-
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/controller/Controller.php b/src/controller/Controller.php
index d9fed7ad7..a1a3bea9a 100644
--- a/src/controller/Controller.php
+++ b/src/controller/Controller.php
@@ -42,8 +42,6 @@ public function __construct($model)
foreach ($this->model->getConfig()->getLanguages() as $langcode => $locale) {
$this->languages[$langcode] = array('locale' => $locale);
$this->setLanguageProperties($langcode);
- //$this->languages[$langcode]['name'] = gettext('in_this_language');
- //$this->languages[$langcode]['lemma'] = Punic\Language::getName($langcode, $langcode);
}
}
diff --git a/src/controller/WebController.php b/src/controller/WebController.php
index 76fc1c7a0..e352b7612 100644
--- a/src/controller/WebController.php
+++ b/src/controller/WebController.php
@@ -19,6 +19,7 @@ class WebController extends Controller
*/
public $twig;
public $honeypot;
+ public $translator;
/**
* Constructor for the WebController.
@@ -67,10 +68,14 @@ public function __construct($model)
$this->twig->addFilter($langFilter);
foreach( $this->languages as $langcode => $value ) {
- $translator = new Translator($langcode);
- $translator->addLoader('po', new PoFileLoader());
- $translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $langcode . '.po', $langcode);
- $this->languages[$langcode]['name'] = $translator->trans('in_this_language');
+ if (is_null($this->translator)) {
+ $this->translator = new Translator($langcode);
+ $this->twig->addExtension(new TranslationExtension($this->translator));
+ }
+ $this->translator->addLoader('po', new PoFileLoader());
+ $this->translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $langcode . '.po', $langcode);
+ $this->translator->setlocale($langcode);
+ $this->languages[$langcode]['name'] = $this->translator->trans('in_this_language');
}
// create the honeypot
@@ -83,14 +88,11 @@ public function __construct($model)
/**
* Creates and registers the translation extension and loads translation file.
- * @param string $lang two character language code
+ * @param string $lang two character language code 'fi' or compound language (locale) name such as 'fi_FI'
*/
- public function addTranslations($lang)
+ public function setTranslationLocale($locale)
{
- $translator = new Translator($lang);
- $translator->addLoader('po', new PoFileLoader());
- $translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $lang . '.po', $lang);
- $this->twig->addExtension(new TranslationExtension($translator));
+ $this->translator->setlocale($locale);
}
/**
diff --git a/src/index.php b/src/index.php
index b11d8b2b2..321690a52 100644
--- a/src/index.php
+++ b/src/index.php
@@ -31,7 +31,7 @@
} else {
if (array_key_exists($parts[1], $config->getLanguages())) { // global pages
$request->setLang($parts[1]);
- $controller->addTranslations($parts[1]);
+ $controller->setTranslationLocale($parts[1]);
$content_lang = $request->getQueryParam('clang');
$request->setContentLang($content_lang);
($parts[2] == 'about' || $parts[2] == 'feedback' || $parts[2] == 'search') ? $request->setPage($parts[2]) : $request->setPage('');
From 9510b570cdd974d45d7899584981dcfcdcd2184c Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Wed, 31 May 2023 17:07:19 +0300
Subject: [PATCH 03/10] Dropped gettext from CI.yml and fixed PHP style
---
.github/workflows/ci.yml | 4 ++--
src/controller/WebController.php | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2a7919986..3f1b9c801 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -48,7 +48,7 @@ jobs:
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php_version }}
- php_extensions: gettext intl xsl pcov
+ php_extensions: intl xsl pcov
- name: Install Node
uses: actions/setup-node@v3
@@ -71,7 +71,7 @@ jobs:
with:
version: 9.5
php_version: ${{ matrix.php_version }}
- php_extensions: gettext intl xsl pcov
+ php_extensions: intl xsl pcov
memory_limit: 512M
configuration: phpunit.xml
diff --git a/src/controller/WebController.php b/src/controller/WebController.php
index e352b7612..f75fa7a36 100644
--- a/src/controller/WebController.php
+++ b/src/controller/WebController.php
@@ -7,6 +7,7 @@
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\PoFileLoader;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
+
/**
* WebController is an extension of the Controller that handles all
* the requests originating from the view of the website.
@@ -67,7 +68,7 @@ public function __construct($model)
});
$this->twig->addFilter($langFilter);
- foreach( $this->languages as $langcode => $value ) {
+ foreach($this->languages as $langcode => $value) {
if (is_null($this->translator)) {
$this->translator = new Translator($langcode);
$this->twig->addExtension(new TranslationExtension($this->translator));
From 5c730cf384246708fb21d7fc34a52cbb7280b104 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Wed, 31 May 2023 17:27:58 +0300
Subject: [PATCH 04/10] Removed gettext from composer.json
---
composer.json | 1 -
1 file changed, 1 deletion(-)
diff --git a/composer.json b/composer.json
index a92884363..966c91710 100644
--- a/composer.json
+++ b/composer.json
@@ -12,7 +12,6 @@
"willdurand/negotiation": "3.1.*",
"punic/punic": "3.5.1",
"ml/json-ld": "1.*",
- "ext-gettext": "*",
"ext-intl": "*",
"ext-mbstring": "*",
"ext-xsl": "*",
From c05883bdbf5cfa1c7b653c8dfc364de5de2e7314 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Thu, 1 Jun 2023 19:13:38 +0300
Subject: [PATCH 05/10] Removed gettext functions
---
src/controller/Controller.php | 40 +++++++++++----------
src/controller/RestController.php | 22 ++++++------
src/controller/WebController.php | 46 +++++++++---------------
src/index.php | 2 +-
src/model/BaseConfig.php | 2 +-
src/model/Concept.php | 32 ++++++++---------
src/model/ConceptProperty.php | 4 +--
src/model/ConceptPropertyValue.php | 2 +-
src/model/DataObject.php | 19 +++++++---
src/model/Model.php | 56 ++++++++++++++++++++++++++++--
src/model/Vocabulary.php | 24 ++++++-------
src/model/VocabularyCategory.php | 2 +-
src/model/VocabularyConfig.php | 2 +-
13 files changed, 154 insertions(+), 99 deletions(-)
diff --git a/src/controller/Controller.php b/src/controller/Controller.php
index a1a3bea9a..9aa501e87 100644
--- a/src/controller/Controller.php
+++ b/src/controller/Controller.php
@@ -21,6 +21,8 @@ class Controller
protected $languages;
+ protected $translator;
+
/**
* Initializes the Model object.
*/
@@ -30,37 +32,39 @@ public function __construct($model)
$this->negotiator = new \Negotiation\Negotiator();
$domain = 'skosmos';
- // Specify the location of the translation tables
- bindtextdomain($domain, 'resource/translations');
- bind_textdomain_codeset($domain, 'UTF-8');
-
- // Choose domain for translations
- textdomain($domain);
-
// Build arrays of language information, with 'locale' and 'name' keys
$this->languages = array();
foreach ($this->model->getConfig()->getLanguages() as $langcode => $locale) {
$this->languages[$langcode] = array('locale' => $locale);
- $this->setLanguageProperties($langcode);
+ $this->setLocale($langcode);
+ $this->translator = $this->model->getTranslator();
+ $this->translator->setlocale($langcode);
+ $this->languages[$langcode]['name'] = $this->translator->trans('in_this_language');
+ $this->languages[$langcode]['lemma'] = Punic\Language::getName($langcode, $langcode);
}
}
/**
- * Sets the locale language properties from the parameter (used by gettext and some Model classes).
- * @param string $lang language parameter eg. 'fi' for Finnish.
+ * Changes translation language for Symfony Translator.
+ * @param string $lang two character language code 'fi' or compound language (locale) name such as 'fi_FI'
*/
- public function setLanguageProperties($lang)
+ public function setLocale($locale)
{
- if (array_key_exists($lang, $this->languages)) {
- $locale = $this->languages[$lang]['locale'];
- putenv("LANGUAGE=$locale");
- putenv("LC_ALL=$locale");
- setlocale(LC_ALL, $locale);
- } else {
- trigger_error("Unsupported language '$lang', not setting locale", E_USER_WARNING);
+ if (!is_null($this->translator)) {
+ $this->model->setlocale($locale);
}
}
+ /**
+ * Get text translated in language set by SetLocale function
+ *
+ * @param string $text text to be translated
+ */
+ protected function getText($text)
+ {
+ return $this->model->getText($text);
+ }
+
/**
* Negotiate a MIME type according to the proposed format, the list of valid
* formats, and an optional proposed format.
diff --git a/src/controller/RestController.php b/src/controller/RestController.php
index 38fcafb5b..4852f62e9 100644
--- a/src/controller/RestController.php
+++ b/src/controller/RestController.php
@@ -64,7 +64,7 @@ public function vocabularies($request)
return $this->returnError(400, "Bad Request", "lang parameter missing");
}
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$vocabs = array();
foreach ($this->model->getVocabularies() as $voc) {
@@ -259,7 +259,7 @@ public function vocabularyStatistics($request)
if ($this->notModified($request->getVocab())) {
return null;
}
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$arrayClass = $request->getVocab()->getConfig()->getArrayClassURI();
$groupClass = $request->getVocab()->getConfig()->getGroupClassURI();
$queryLang = $request->getQueryParam('lang') ?? $request->getLang();
@@ -294,7 +294,7 @@ public function vocabularyStatistics($request)
'title' => $request->getVocab()->getConfig()->getTitle(),
'concepts' => array(
'class' => 'http://www.w3.org/2004/02/skos/core#Concept',
- 'label' => gettext('skos:Concept'),
+ 'label' => $this->getText('skos:Concept'),
'count' => isset($vocabStats['http://www.w3.org/2004/02/skos/core#Concept']) ? $vocabStats['http://www.w3.org/2004/02/skos/core#Concept']['count'] : 0,
'deprecatedCount' => isset($vocabStats['http://www.w3.org/2004/02/skos/core#Concept']) ? $vocabStats['http://www.w3.org/2004/02/skos/core#Concept']['deprecatedCount'] : 0,
),
@@ -304,7 +304,7 @@ public function vocabularyStatistics($request)
if (isset($vocabStats['http://www.w3.org/2004/02/skos/core#Collection'])) {
$ret['conceptGroups'] = array(
'class' => 'http://www.w3.org/2004/02/skos/core#Collection',
- 'label' => gettext('skos:Collection'),
+ 'label' => $this->getText('skos:Collection'),
'count' => $vocabStats['http://www.w3.org/2004/02/skos/core#Collection']['count'],
'deprecatedCount' => $vocabStats['http://www.w3.org/2004/02/skos/core#Collection']['deprecatedCount'],
);
@@ -312,14 +312,14 @@ public function vocabularyStatistics($request)
} elseif (isset($vocabStats[$groupClass])) {
$ret['conceptGroups'] = array(
'class' => $groupClass,
- 'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : gettext(EasyRdf\RdfNamespace::shorten($groupClass)),
+ 'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : $this->getText(EasyRdf\RdfNamespace::shorten($groupClass)),
'count' => $vocabStats[$groupClass]['count'],
'deprecatedCount' => $vocabStats[$groupClass]['deprecatedCount'],
);
} elseif (isset($vocabStats[$arrayClass])) {
$ret['arrays'] = array(
'class' => $arrayClass,
- 'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : gettext(EasyRdf\RdfNamespace::shorten($arrayClass)),
+ 'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : $this->getText(EasyRdf\RdfNamespace::shorten($arrayClass)),
'count' => $vocabStats[$arrayClass]['count'],
'deprecatedCount' => $vocabStats[$arrayClass]['deprecatedCount'],
);
@@ -338,7 +338,7 @@ public function labelStatistics($request)
return null;
}
$lang = $request->getLang();
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$vocabStats = $request->getVocab()->getLabelStatistics();
/* encode the results in a JSON-LD compatible array */
@@ -398,7 +398,7 @@ public function types($request)
return null;
}
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$queriedtypes = $this->model->getTypes($vocid, $request->getLang());
@@ -687,7 +687,7 @@ public function data($request)
*/
public function mappings(Request $request)
{
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$vocab = $request->getVocab();
if ($this->notModified($vocab)) {
return null;
@@ -774,7 +774,7 @@ public function label($request)
public function indexLetters($request)
{
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$letters = $request->getVocab()->getAlphabet($request->getLang());
$ret = array_merge_recursive(
@@ -802,7 +802,7 @@ public function indexLetters($request)
public function indexConcepts($letter, $request)
{
- $this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$offset_param = $request->getQueryParam('offset');
$offset = (is_numeric($offset_param) && $offset_param >= 0) ? $offset_param : 0;
diff --git a/src/controller/WebController.php b/src/controller/WebController.php
index f75fa7a36..0bdb9f3dc 100644
--- a/src/controller/WebController.php
+++ b/src/controller/WebController.php
@@ -4,8 +4,6 @@
* Importing the dependencies.
*/
use Punic\Language;
-use Symfony\Component\Translation\Translator;
-use Symfony\Component\Translation\Loader\PoFileLoader;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
/**
@@ -68,16 +66,8 @@ public function __construct($model)
});
$this->twig->addFilter($langFilter);
- foreach($this->languages as $langcode => $value) {
- if (is_null($this->translator)) {
- $this->translator = new Translator($langcode);
- $this->twig->addExtension(new TranslationExtension($this->translator));
- }
- $this->translator->addLoader('po', new PoFileLoader());
- $this->translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $langcode . '.po', $langcode);
- $this->translator->setlocale($langcode);
- $this->languages[$langcode]['name'] = $this->translator->trans('in_this_language');
- }
+ $this->translator = $model->getTranslator();
+ $this->twig->addExtension(new TranslationExtension($this->translator));
// create the honeypot
$this->honeypot = new \Honeypot();
@@ -87,15 +77,6 @@ public function __construct($model)
$this->twig->addGlobal('honeypot', $this->honeypot);
}
- /**
- * Creates and registers the translation extension and loads translation file.
- * @param string $lang two character language code 'fi' or compound language (locale) name such as 'fi_FI'
- */
- public function setTranslationLocale($locale)
- {
- $this->translator->setlocale($locale);
- }
-
/**
* Guess the language of the user. Return a language string that is one
* of the supported languages defined in the $LANGUAGES setting, e.g. "fi".
@@ -162,7 +143,8 @@ private function listStyle()
public function invokeLandingPage($request)
{
// set language parameters for gettext
- $this->setLanguageProperties($request->getLang());
+ //$this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
// load template
$template = $this->twig->loadTemplate('landing.twig');
// set template variables
@@ -192,7 +174,7 @@ public function invokeLandingPage($request)
public function invokeVocabularyConcept(Request $request)
{
$lang = $request->getLang();
- $this->setLanguageProperties($lang);
+ $this->setLocale($request->getLang());
$vocab = $request->getVocab();
$langcodes = $vocab->getConfig()->getShowLangCodes();
@@ -233,7 +215,8 @@ public function invokeVocabularyConcept(Request $request)
public function invokeFeedbackForm($request)
{
$template = $this->twig->loadTemplate('feedback.twig');
- $this->setLanguageProperties($request->getLang());
+ //$this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$vocabList = $this->model->getVocabularyList(false);
$vocab = $request->getVocab();
@@ -341,7 +324,8 @@ public function sendFeedback($request, $message, $messageSubject, $fromName = nu
public function invokeAboutPage($request)
{
$template = $this->twig->loadTemplate('about.twig');
- $this->setLanguageProperties($request->getLang());
+ //$this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$url = $request->getServerConstant('HTTP_HOST');
echo $template->render(
@@ -360,7 +344,8 @@ public function invokeGlobalSearch($request)
{
$lang = $request->getLang();
$template = $this->twig->loadTemplate('global-search.twig');
- $this->setLanguageProperties($lang);
+ //$this->setLanguageProperties($lang);
+ $this->setLocale($request->getLang());
$parameters = new ConceptSearchParameters($request, $this->model->getConfig());
@@ -429,7 +414,8 @@ public function invokeGlobalSearch($request)
public function invokeVocabularySearch($request)
{
$template = $this->twig->loadTemplate('vocab-search.twig');
- $this->setLanguageProperties($request->getLang());
+ //$this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
$vocab = $request->getVocab();
$searchResults = null;
try {
@@ -503,7 +489,8 @@ public function invokeVocabularyHome($request)
{
$lang = $request->getLang();
// set language parameters for gettext
- $this->setLanguageProperties($lang);
+ //$this->setLanguageProperties($lang);
+ $this->setLocale($request->getLang());
$vocab = $request->getVocab();
$defaultView = $vocab->getConfig()->getDefaultSidebarView();
@@ -535,7 +522,8 @@ public function invokeVocabularyHome($request)
*/
public function invokeGenericErrorPage($request, $message = null)
{
- $this->setLanguageProperties($request->getLang());
+ //$this->setLanguageProperties($request->getLang());
+ $this->setLocale($request->getLang());
header("HTTP/1.0 404 Not Found");
$template = $this->twig->loadTemplate('error.twig');
echo $template->render(
diff --git a/src/index.php b/src/index.php
index 321690a52..d01b308e5 100644
--- a/src/index.php
+++ b/src/index.php
@@ -31,7 +31,7 @@
} else {
if (array_key_exists($parts[1], $config->getLanguages())) { // global pages
$request->setLang($parts[1]);
- $controller->setTranslationLocale($parts[1]);
+ $controller->setLocale($parts[1]);
$content_lang = $request->getQueryParam('clang');
$request->setContentLang($content_lang);
($parts[2] == 'about' || $parts[2] == 'feedback' || $parts[2] == 'search') ? $request->setPage($parts[2]) : $request->setPage('');
diff --git a/src/model/BaseConfig.php b/src/model/BaseConfig.php
index da909dca5..4e34bb14e 100644
--- a/src/model/BaseConfig.php
+++ b/src/model/BaseConfig.php
@@ -46,7 +46,7 @@ protected function getResources($property)
protected function getLiteral($property, $default=null, $lang=null)
{
if (!isset($lang)) {
- $lang = $this->getEnvLang();
+ $lang = $this->getLang();
}
$literal = $this->getResource()->getLiteral($property, $lang);
diff --git a/src/model/Concept.php b/src/model/Concept.php
index b16b28aaa..fd6c0e19b 100644
--- a/src/model/Concept.php
+++ b/src/model/Concept.php
@@ -415,7 +415,7 @@ public function getMappingProperties(array $whitelist = null)
if (in_array($prop, $this->MAPPING_PROPERTIES) && !in_array($prop, $this->DELETED_PROPERTIES)) {
$propres = new EasyRdf\Resource($prop, $this->graph);
- $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label(); // current language
+ $proplabel = $propres->label($this->getLang()) ? $propres->label($this->getLang()) : $propres->label(); // current language
$propobj = new ConceptProperty($prop, $proplabel);
if ($propobj->getLabel() !== null) {
// only display properties for which we have a label
@@ -513,30 +513,30 @@ public function getProperties()
if (!in_array($prop, $this->deleted) || ($this->isGroup() === false && $prop === 'skos:member')) {
// retrieve property label and super properties from the current vocabulary first
$propres = new EasyRdf\Resource($prop, $this->graph);
- $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label();
+ $proplabel = $propres->label($this->getLang()) ? $propres->label($this->getLang()) : $propres->label();
- $prophelp = $propres->getLiteral('rdfs:comment|skos:definition', $this->getEnvLang());
+ $prophelp = $propres->getLiteral('rdfs:comment|skos:definition', $this->getLang());
if ($prophelp === null) {
// try again without language restriction
$prophelp = $propres->getLiteral('rdfs:comment|skos:definition');
}
- // check if the property is one of the well-known properties for which we have a gettext translation
+ // check if the property is one of the well-known properties for which we have a translation
// if it is then we can skip the additional lookups in the default graph
$propkey = (substr($prop, 0, 5) == 'dc11:') ?
str_replace('dc11:', 'dc:', $prop) : $prop;
- $is_well_known = (gettext($propkey) != $propkey);
+ $is_well_known = ($this->model->getText($propkey) != $propkey);
// if not found in current vocabulary, look up in the default graph to be able
// to read an ontology loaded in a separate graph
// note that this imply that the property has an rdf:type declared for the query to work
if(!$is_well_known && !$proplabel) {
- $envLangLabels = $this->model->getDefaultSparql()->queryLabel($longUri, $this->getEnvLang());
+ $envLangLabels = $this->model->getDefaultSparql()->queryLabel($longUri, $this->getLang());
$defaultPropLabel = $this->model->getDefaultSparql()->queryLabel($longUri, '');
if($envLangLabels) {
- $proplabel = $envLangLabels[$this->getEnvLang()];
+ $proplabel = $envLangLabels[$this->getLang()];
} else {
if($defaultPropLabel) {
$proplabel = $defaultPropLabel[''];
@@ -733,14 +733,14 @@ public function getDate()
// making a human readable string from the timestamps
if ($created != '') {
- $ret = gettext('skosmos:created') . ' ' . (Punic\Calendar::formatDate($created, 'short', $this->getEnvLang()));
+ $ret = $this->model->getText('skosmos:created') . ' ' . (Punic\Calendar::formatDate($created, 'short', $this->getLang()));
}
if ($modified != '') {
if ($created != '') {
- $ret .= ', ' . gettext('skosmos:modified') . ' ' . (Punic\Calendar::formatDate($modified, 'short', $this->getEnvLang()));
+ $ret .= ', ' . $this->model->getText('skosmos:modified') . ' ' . (Punic\Calendar::formatDate($modified, 'short', $this->getLang()));
} else {
- $ret .= ' ' . ucfirst(gettext('skosmos:modified')) . ' ' . (Punic\Calendar::formatDate($modified, 'short', $this->getEnvLang()));
+ $ret .= ' ' . ucfirst($this->model->getText('skosmos:modified')) . ' ' . (Punic\Calendar::formatDate($modified, 'short', $this->getLang()));
}
}
@@ -749,11 +749,11 @@ public function getDate()
$ret = '';
if ($this->resource->get('dc:modified')) {
$modified = (string) $this->resource->get('dc:modified');
- $ret = gettext('skosmos:modified') . ' ' . $modified;
+ $ret = $this->model->getText('skosmos:modified') . ' ' . $modified;
}
if ($this->resource->get('dc:created')) {
$created .= (string) $this->resource->get('dc:created');
- $ret .= ' ' . gettext('skosmos:created') . ' ' . $created;
+ $ret .= ' ' . $this->model->getText('skosmos:created') . ' ' . $created;
}
}
return $ret;
@@ -846,7 +846,7 @@ public function getArrayProperties()
/**
* Given a language code, gets its name in UI language via Punic or alternatively
- * tries to search for a gettext translation.
+ * tries to search for a model->getText translation.
* @param string $langCode
* @return string e.g. 'English'
*/
@@ -855,7 +855,7 @@ private function langToString($langCode)
// using empty string as the language name when there is no langcode set
$langName = '';
if (!empty($langCode)) {
- $langName = Punic\Language::getName($langCode, $this->getEnvLang()) !== $langCode ? Punic\Language::getName($langCode, $this->getEnvLang()) : gettext($langCode);
+ $langName = Punic\Language::getName($langCode, $this->getLang()) !== $langCode ? Punic\Language::getName($langCode, $this->getLang()) : $this->model->getText($langCode);
}
return $langName;
}
@@ -875,7 +875,7 @@ private function getForeignLabelList($prop, $key)
foreach ($labels as $lit) {
// filtering away subsets of the current language eg. en vs en-GB
$langCode = strval($lit->getLang());
- if ($langCode != $this->clang && strpos($langCode, $this->getEnvLang() . '-') !== 0) {
+ if ($langCode != $this->clang && strpos($langCode, $this->getLang() . '-') !== 0) {
$ret[$langCode][$key][] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $lit, $prop);
}
}
@@ -921,7 +921,7 @@ public function getAllLabels($property)
// shortening property labels if possible, EasyRdf requires full URIs to be in angle brackets
$property = (EasyRdf\RdfNamespace::shorten($property) !== null) ? EasyRdf\RdfNamespace::shorten($property) : "<$property>";
foreach ($this->resource->allLiterals($property) as $lit) {
- $labels[Punic\Language::getName($lit->getLang(), $this->getEnvLang())][] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $lit, $property);
+ $labels[Punic\Language::getName($lit->getLang(), $this->getLang())][] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $lit, $property);
}
ksort($labels);
return $labels;
diff --git a/src/model/ConceptProperty.php b/src/model/ConceptProperty.php
index c43ded065..2901e1a87 100644
--- a/src/model/ConceptProperty.php
+++ b/src/model/ConceptProperty.php
@@ -47,7 +47,7 @@ public function getLabel()
// we don't maintain DC 1.1 translations separate from DC Terms
$prop = (substr($this->prop, 0, 5) == 'dc11:') ?
str_replace('dc11:', 'dc:', $this->prop) : $this->prop;
- $label = gettext($prop);
+ $label = $this->getText($prop);
if ($label != $prop) {
return $label;
}
@@ -78,7 +78,7 @@ public function getDescription()
$helpprop = $this->prop . "_help";
// see if we have a translation with the help text
- $help = gettext($helpprop);
+ $help = $this->getText($helpprop);
if ($help != $helpprop) {
return $help;
}
diff --git a/src/model/ConceptPropertyValue.php b/src/model/ConceptPropertyValue.php
index 0a4dc5aa4..4206f34ae 100644
--- a/src/model/ConceptPropertyValue.php
+++ b/src/model/ConceptPropertyValue.php
@@ -38,7 +38,7 @@ public function __toString()
public function getLang()
{
- return $this->getEnvLang();
+ return $this->getLang();
}
public function getLabel($lang = '', $fallbackToUri = 'uri')
diff --git a/src/model/DataObject.php b/src/model/DataObject.php
index 55e2afa31..dca42d356 100644
--- a/src/model/DataObject.php
+++ b/src/model/DataObject.php
@@ -131,12 +131,23 @@ protected function mycompare($a, $b)
}
/**
- * Getter function to retrieve the ui language from the locale.
+ * Getter function to retrieve the ui language from Symfony translator.
*/
- public function getEnvLang()
+ public function getLang()
{
- // get language from locale, same as used by gettext, set by Controller
- return substr(getenv("LC_ALL"), 0, 2); // @codeCoverageIgnore
+ if (!is_null($this->model)) {
+ return $this->model->getLocale();
+ }
+ }
+
+ /**
+ * Get text translated in language set by SetLocale function
+ *
+ * @param string $text text to be translated
+ */
+ protected function getText($text)
+ {
+ return $this->model->getText($text);
}
/**
diff --git a/src/model/Model.php b/src/model/Model.php
index d875e0651..83f962d33 100644
--- a/src/model/Model.php
+++ b/src/model/Model.php
@@ -1,5 +1,11 @@
globalConfig = $config;
$this->initializeLogging();
$this->resolver = new Resolver($this);
+
+ foreach ($this->getConfig()->getLanguages() as $langcode => $locale) {
+ if (is_null($this->translator)) {
+ $this->translator = new Translator($langcode);
+ }
+ $this->translator->addLoader('po', new PoFileLoader());
+ $this->translator->addResource('po', __DIR__.'/../../resource/translations/skosmos_' . $langcode . '.po', $langcode);
+ }
}
/**
@@ -131,12 +146,12 @@ public function getTypes($vocid = null, $lang = null)
{
$sparql = (isset($vocid)) ? $this->getVocabulary($vocid)->getSparql() : $this->getDefaultSparql();
$result = $sparql->queryTypes($lang);
-
foreach ($result as $uri => $values) {
if (empty($values)) {
$shorteneduri = EasyRdf\RdfNamespace::shorten($uri);
if ($shorteneduri !== null) {
- $trans = gettext($shorteneduri);
+ $this->translator->setlocale($lang);
+ $trans = $this->getText($shorteneduri);
if ($trans) {
$result[$uri] = array('label' => $trans);
}
@@ -165,6 +180,43 @@ public function getLanguages($lang)
return array_unique($ret);
}
+ /**
+ * Return Symfony Translator object for translations in given language.
+ * @return Translator Translator object from Symfony package
+ */
+ public function getTranslator()
+ {
+ return $this->translator;
+ }
+
+ /**
+ * Sets translation language for Symfony Translator objext
+ * @param string $lang two character language code 'fi' or compound language (locale) name such as 'fi_FI'
+ */
+ public function setLocale($locale)
+ {
+ $this->translator->setlocale($locale);
+ }
+
+ /**
+ * Gets translation language from Symfony Translator objext
+ * @return string $lang two character language code 'fi' or compound language (locale) name such as 'fi_FI'
+ */
+ public function getLocale()
+ {
+ return $this->translator->getlocale();
+ }
+
+ /**
+ * Get text translated in language set by SetLocale function
+ *
+ * @param string $text text to be translated
+ */
+ public function getText($text)
+ {
+ return $this->translator->trans($text);
+ }
+
/**
* returns a concept's RDF data in downloadable format
* @param string $vocid vocabulary id, or null for global data (from all vocabularies)
diff --git a/src/model/Vocabulary.php b/src/model/Vocabulary.php
index 98cd8895c..eb41c8059 100644
--- a/src/model/Vocabulary.php
+++ b/src/model/Vocabulary.php
@@ -147,7 +147,7 @@ public function getInfo($lang = null)
{
$ret = array();
if (!$lang) {
- $lang = $this->getEnvLang();
+ $lang = $this->getLang();
}
// get metadata (literals only e.g. name) from vocabulary configuration file
@@ -249,7 +249,7 @@ public function getInfo($lang = null)
public function getConceptSchemes($lang = '')
{
if ($lang === '') {
- $lang = $this->getEnvLang();
+ $lang = $this->getLang();
}
$conceptSchemes = null;
try {
@@ -303,7 +303,7 @@ public function getConceptScheme(string $defaultConceptSchemeURI)
public function getTopConcepts($conceptScheme = null, $lang = '')
{
if ($lang === '') {
- $lang = $this->getEnvLang();
+ $lang = $this->getLang();
}
$fallback = $this->config->getDefaultLanguage();
@@ -366,7 +366,7 @@ public function getLabelStatistics()
*/
public function getConceptHierarchy($uri, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
$fallback = count($this->config->getLanguageOrder($lang)) > 1 ? $this->config->getLanguageOrder($lang)[1] : $this->config->getDefaultLanguage();
$props = $this->config->getHierarchyProperty();
return $this->getSparql()->queryParentList($uri, $lang, $fallback, $props);
@@ -378,7 +378,7 @@ public function getConceptHierarchy($uri, $lang)
*/
public function getConceptChildren($uri, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
$fallback = count($this->config->getLanguageOrder($lang)) > 1 ? $this->config->getLanguageOrder($lang)[1] : $this->config->getDefaultLanguage();
$props = $this->config->getHierarchyProperty();
return $this->getSparql()->queryChildren($uri, $lang, $fallback, $props);
@@ -391,7 +391,7 @@ public function getConceptChildren($uri, $lang)
*/
public function getConceptNarrowers($uri, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
return $this->getSparql()->queryProperty($uri, 'skos:narrower', $lang);
}
@@ -403,7 +403,7 @@ public function getConceptNarrowers($uri, $lang)
*/
public function getConceptTransitiveNarrowers($uri, $limit, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
return $this->getSparql()->queryTransitiveProperty($uri, array('skos:narrower'), $lang, $limit);
}
@@ -414,7 +414,7 @@ public function getConceptTransitiveNarrowers($uri, $limit, $lang)
*/
public function getConceptBroaders($uri, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
return $this->getSparql()->queryProperty($uri, 'skos:broader', $lang);
}
@@ -427,7 +427,7 @@ public function getConceptBroaders($uri, $lang)
*/
public function getConceptTransitiveBroaders($uri, $limit, $any, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
$fallback = $this->config->getDefaultLanguage();
return $this->getSparql()->queryTransitiveProperty($uri, array('skos:broader'), $lang, $limit, $any, $fallback);
}
@@ -439,7 +439,7 @@ public function getConceptTransitiveBroaders($uri, $limit, $any, $lang)
*/
public function getConceptRelateds($uri, $lang)
{
- $lang = $lang ? $lang : $this->getEnvLang();
+ $lang = $lang ? $lang : $this->getLang();
return $this->getSparql()->queryProperty($uri, 'skos:related', $lang);
}
@@ -470,7 +470,7 @@ public function getConceptInfo($uri, $clang)
public function listConceptGroups($clang = null)
{
if ($clang === null || $clang == '') {
- $clang = $this->getEnvLang();
+ $clang = $this->getLang();
}
$ret = array();
@@ -495,7 +495,7 @@ public function listConceptGroups($clang = null)
public function listConceptGroupContents($glname, $clang)
{
if (!$clang) {
- $clang = $this->config->getEnvLang();
+ $clang = $this->getLang();
}
$ret = array();
diff --git a/src/model/VocabularyCategory.php b/src/model/VocabularyCategory.php
index 1ef97397f..894d85991 100644
--- a/src/model/VocabularyCategory.php
+++ b/src/model/VocabularyCategory.php
@@ -33,7 +33,7 @@ public function getVocabularies()
public function getTitle()
{
if ($this->resource) {
- $label = $this->resource->label($this->getEnvLang());
+ $label = $this->resource->label($this->getLang());
return is_null($label) ? $this->resource->localName() : $label->getValue();
}
return gettext('Vocabularies');
diff --git a/src/model/VocabularyConfig.php b/src/model/VocabularyConfig.php
index c1b8953f4..869a76e8e 100644
--- a/src/model/VocabularyConfig.php
+++ b/src/model/VocabularyConfig.php
@@ -534,7 +534,7 @@ public function getLanguages()
$langs = $this->resource->allLiterals('skosmos:language');
$ret = array();
foreach ($langs as $lang) {
- $langlit = Punic\Language::getName($lang->getValue(), $this->getEnvLang());
+ $langlit = Punic\Language::getName($lang->getValue(), $this->getLang());
$ret[$langlit] = $lang->getValue();
}
ksort($ret);
From ca633beadd087e01e92d203a811befd03fd3cc00 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Tue, 29 Aug 2023 14:11:35 +0300
Subject: [PATCH 06/10] Changed all translations to use Model's GetText
function
---
src/controller/Controller.php | 23 +----------------------
src/controller/RestController.php | 22 +++++++++++-----------
src/controller/WebController.php | 20 ++++++++------------
src/index.php | 2 +-
src/model/Concept.php | 10 +++++-----
src/model/ConceptMappingPropertyValue.php | 4 ++--
src/model/ConceptProperty.php | 8 +++++---
src/model/ConceptPropertyValue.php | 4 ++--
src/model/DataObject.php | 10 ----------
src/model/Model.php | 2 +-
src/model/VocabularyCategory.php | 2 +-
tests/ConceptPropertyTest.php | 8 ++++----
tests/ConceptPropertyValueLiteralTest.php | 1 +
tests/ConceptTest.php | 1 +
tests/ModelTest.php | 10 ++++++++++
15 files changed, 53 insertions(+), 74 deletions(-)
diff --git a/src/controller/Controller.php b/src/controller/Controller.php
index 9aa501e87..233d55b0a 100644
--- a/src/controller/Controller.php
+++ b/src/controller/Controller.php
@@ -36,7 +36,7 @@ public function __construct($model)
$this->languages = array();
foreach ($this->model->getConfig()->getLanguages() as $langcode => $locale) {
$this->languages[$langcode] = array('locale' => $locale);
- $this->setLocale($langcode);
+ $this->model->setLocale($langcode);
$this->translator = $this->model->getTranslator();
$this->translator->setlocale($langcode);
$this->languages[$langcode]['name'] = $this->translator->trans('in_this_language');
@@ -44,27 +44,6 @@ public function __construct($model)
}
}
- /**
- * Changes translation language for Symfony Translator.
- * @param string $lang two character language code 'fi' or compound language (locale) name such as 'fi_FI'
- */
- public function setLocale($locale)
- {
- if (!is_null($this->translator)) {
- $this->model->setlocale($locale);
- }
- }
-
- /**
- * Get text translated in language set by SetLocale function
- *
- * @param string $text text to be translated
- */
- protected function getText($text)
- {
- return $this->model->getText($text);
- }
-
/**
* Negotiate a MIME type according to the proposed format, the list of valid
* formats, and an optional proposed format.
diff --git a/src/controller/RestController.php b/src/controller/RestController.php
index 4852f62e9..7dea4d328 100644
--- a/src/controller/RestController.php
+++ b/src/controller/RestController.php
@@ -64,7 +64,7 @@ public function vocabularies($request)
return $this->returnError(400, "Bad Request", "lang parameter missing");
}
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocabs = array();
foreach ($this->model->getVocabularies() as $voc) {
@@ -259,7 +259,7 @@ public function vocabularyStatistics($request)
if ($this->notModified($request->getVocab())) {
return null;
}
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$arrayClass = $request->getVocab()->getConfig()->getArrayClassURI();
$groupClass = $request->getVocab()->getConfig()->getGroupClassURI();
$queryLang = $request->getQueryParam('lang') ?? $request->getLang();
@@ -294,7 +294,7 @@ public function vocabularyStatistics($request)
'title' => $request->getVocab()->getConfig()->getTitle(),
'concepts' => array(
'class' => 'http://www.w3.org/2004/02/skos/core#Concept',
- 'label' => $this->getText('skos:Concept'),
+ 'label' => $this->model->getText('skos:Concept'),
'count' => isset($vocabStats['http://www.w3.org/2004/02/skos/core#Concept']) ? $vocabStats['http://www.w3.org/2004/02/skos/core#Concept']['count'] : 0,
'deprecatedCount' => isset($vocabStats['http://www.w3.org/2004/02/skos/core#Concept']) ? $vocabStats['http://www.w3.org/2004/02/skos/core#Concept']['deprecatedCount'] : 0,
),
@@ -304,7 +304,7 @@ public function vocabularyStatistics($request)
if (isset($vocabStats['http://www.w3.org/2004/02/skos/core#Collection'])) {
$ret['conceptGroups'] = array(
'class' => 'http://www.w3.org/2004/02/skos/core#Collection',
- 'label' => $this->getText('skos:Collection'),
+ 'label' => $this->model->getText('skos:Collection'),
'count' => $vocabStats['http://www.w3.org/2004/02/skos/core#Collection']['count'],
'deprecatedCount' => $vocabStats['http://www.w3.org/2004/02/skos/core#Collection']['deprecatedCount'],
);
@@ -312,14 +312,14 @@ public function vocabularyStatistics($request)
} elseif (isset($vocabStats[$groupClass])) {
$ret['conceptGroups'] = array(
'class' => $groupClass,
- 'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : $this->getText(EasyRdf\RdfNamespace::shorten($groupClass)),
+ 'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : $this->model->getText(EasyRdf\RdfNamespace::shorten($groupClass)),
'count' => $vocabStats[$groupClass]['count'],
'deprecatedCount' => $vocabStats[$groupClass]['deprecatedCount'],
);
} elseif (isset($vocabStats[$arrayClass])) {
$ret['arrays'] = array(
'class' => $arrayClass,
- 'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : $this->getText(EasyRdf\RdfNamespace::shorten($arrayClass)),
+ 'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : $this->model->getText(EasyRdf\RdfNamespace::shorten($arrayClass)),
'count' => $vocabStats[$arrayClass]['count'],
'deprecatedCount' => $vocabStats[$arrayClass]['deprecatedCount'],
);
@@ -338,7 +338,7 @@ public function labelStatistics($request)
return null;
}
$lang = $request->getLang();
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocabStats = $request->getVocab()->getLabelStatistics();
/* encode the results in a JSON-LD compatible array */
@@ -398,7 +398,7 @@ public function types($request)
return null;
}
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$queriedtypes = $this->model->getTypes($vocid, $request->getLang());
@@ -687,7 +687,7 @@ public function data($request)
*/
public function mappings(Request $request)
{
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
if ($this->notModified($vocab)) {
return null;
@@ -774,7 +774,7 @@ public function label($request)
public function indexLetters($request)
{
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$letters = $request->getVocab()->getAlphabet($request->getLang());
$ret = array_merge_recursive(
@@ -802,7 +802,7 @@ public function indexLetters($request)
public function indexConcepts($letter, $request)
{
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$offset_param = $request->getQueryParam('offset');
$offset = (is_numeric($offset_param) && $offset_param >= 0) ? $offset_param : 0;
diff --git a/src/controller/WebController.php b/src/controller/WebController.php
index 0bdb9f3dc..fa00c682b 100644
--- a/src/controller/WebController.php
+++ b/src/controller/WebController.php
@@ -142,9 +142,7 @@ private function listStyle()
*/
public function invokeLandingPage($request)
{
- // set language parameters for gettext
- //$this->setLanguageProperties($request->getLang());
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
// load template
$template = $this->twig->loadTemplate('landing.twig');
// set template variables
@@ -174,7 +172,7 @@ public function invokeLandingPage($request)
public function invokeVocabularyConcept(Request $request)
{
$lang = $request->getLang();
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
$langcodes = $vocab->getConfig()->getShowLangCodes();
@@ -216,7 +214,7 @@ public function invokeFeedbackForm($request)
{
$template = $this->twig->loadTemplate('feedback.twig');
//$this->setLanguageProperties($request->getLang());
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocabList = $this->model->getVocabularyList(false);
$vocab = $request->getVocab();
@@ -325,7 +323,7 @@ public function invokeAboutPage($request)
{
$template = $this->twig->loadTemplate('about.twig');
//$this->setLanguageProperties($request->getLang());
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$url = $request->getServerConstant('HTTP_HOST');
echo $template->render(
@@ -345,7 +343,7 @@ public function invokeGlobalSearch($request)
$lang = $request->getLang();
$template = $this->twig->loadTemplate('global-search.twig');
//$this->setLanguageProperties($lang);
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$parameters = new ConceptSearchParameters($request, $this->model->getConfig());
@@ -415,7 +413,7 @@ public function invokeVocabularySearch($request)
{
$template = $this->twig->loadTemplate('vocab-search.twig');
//$this->setLanguageProperties($request->getLang());
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
$searchResults = null;
try {
@@ -488,9 +486,7 @@ public function invokeVocabularySearch($request)
public function invokeVocabularyHome($request)
{
$lang = $request->getLang();
- // set language parameters for gettext
- //$this->setLanguageProperties($lang);
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
$defaultView = $vocab->getConfig()->getDefaultSidebarView();
@@ -523,7 +519,7 @@ public function invokeVocabularyHome($request)
public function invokeGenericErrorPage($request, $message = null)
{
//$this->setLanguageProperties($request->getLang());
- $this->setLocale($request->getLang());
+ $this->model->setLocale($request->getLang());
header("HTTP/1.0 404 Not Found");
$template = $this->twig->loadTemplate('error.twig');
echo $template->render(
diff --git a/src/index.php b/src/index.php
index d01b308e5..eb23f7d94 100644
--- a/src/index.php
+++ b/src/index.php
@@ -31,7 +31,7 @@
} else {
if (array_key_exists($parts[1], $config->getLanguages())) { // global pages
$request->setLang($parts[1]);
- $controller->setLocale($parts[1]);
+ $model->setLocale($parts[1]);
$content_lang = $request->getQueryParam('clang');
$request->setContentLang($content_lang);
($parts[2] == 'about' || $parts[2] == 'feedback' || $parts[2] == 'search') ? $request->setPage($parts[2]) : $request->setPage('');
diff --git a/src/model/Concept.php b/src/model/Concept.php
index fd6c0e19b..2384ef47b 100644
--- a/src/model/Concept.php
+++ b/src/model/Concept.php
@@ -416,7 +416,7 @@ public function getMappingProperties(array $whitelist = null)
if (in_array($prop, $this->MAPPING_PROPERTIES) && !in_array($prop, $this->DELETED_PROPERTIES)) {
$propres = new EasyRdf\Resource($prop, $this->graph);
$proplabel = $propres->label($this->getLang()) ? $propres->label($this->getLang()) : $propres->label(); // current language
- $propobj = new ConceptProperty($prop, $proplabel);
+ $propobj = new ConceptProperty($this->model, $prop, $proplabel);
if ($propobj->getLabel() !== null) {
// only display properties for which we have a label
$ret[$prop] = $propobj;
@@ -561,7 +561,7 @@ public function getProperties()
$superprop = EasyRdf\RdfNamespace::shorten($superprop) ? EasyRdf\RdfNamespace::shorten($superprop) : $superprop;
}
$sort_by_notation = $this->vocab->getConfig()->getSortByNotation();
- $propobj = new ConceptProperty($prop, $proplabel, $prophelp, $superprop, $sort_by_notation);
+ $propobj = new ConceptProperty($this->model, $prop, $proplabel, $prophelp, $superprop, $sort_by_notation);
if ($propobj->getLabel() !== null) {
// only display properties for which we have a label
@@ -618,7 +618,7 @@ public function getProperties()
}
}
- $groupPropObj = new ConceptProperty('skosmos:memberOf', null);
+ $groupPropObj = new ConceptProperty($this->model, 'skosmos:memberOf', null);
foreach ($this->getGroupProperties() as $propVals) {
foreach ($propVals as $propVal) {
$groupPropObj->addValue($propVal);
@@ -626,7 +626,7 @@ public function getProperties()
}
$ret['skosmos:memberOf'] = $groupPropObj;
- $arrayPropObj = new ConceptProperty('skosmos:memberOfArray', null);
+ $arrayPropObj = new ConceptProperty($this->model, 'skosmos:memberOfArray', null);
foreach ($this->getArrayProperties() as $propVals) {
foreach ($propVals as $propVal) {
$arrayPropObj->addValue($propVal);
@@ -846,7 +846,7 @@ public function getArrayProperties()
/**
* Given a language code, gets its name in UI language via Punic or alternatively
- * tries to search for a model->getText translation.
+ * tries to search for getText translation from Model.
* @param string $langCode
* @return string e.g. 'English'
*/
diff --git a/src/model/ConceptMappingPropertyValue.php b/src/model/ConceptMappingPropertyValue.php
index d7030dcbc..4eb0ea223 100644
--- a/src/model/ConceptMappingPropertyValue.php
+++ b/src/model/ConceptMappingPropertyValue.php
@@ -196,12 +196,12 @@ public function asJskos($queryExVocabs = true, $lang = null, $hrefLink = null)
'hrefLink' => $hrefLink, // link to resource as displayed in the UI
'lang' => $propertyLang, // TBD: could it be part of the prefLabel?
'vocabName' => (string) $this->getVocabName(), // vocabulary as displayed in the UI
- 'typeLabel' => gettext($this->type), // a text used in the UI instead of, for example, skos:closeMatch
+ 'typeLabel' => $this->model->getText($this->type), // a text used in the UI instead of, for example, skos:closeMatch
];
$helpprop = $this->type . "_help";
// see if we have a translation for the property help text
- $help = gettext($helpprop);
+ $help = $this->model->getText($helpprop);
if ($help != $helpprop) {
$ret['description'] = $help;
}
diff --git a/src/model/ConceptProperty.php b/src/model/ConceptProperty.php
index 2901e1a87..64bae2c9b 100644
--- a/src/model/ConceptProperty.php
+++ b/src/model/ConceptProperty.php
@@ -21,14 +21,16 @@ class ConceptProperty
/**
* Label parameter seems to be optional in this phase.
+ * @param string $model Model object for using Symfony translator
* @param string $prop property type eg. 'rdf:type'.
* @param string $label property label
* @param string $tooltip property tooltip/description
* @param string $super URI of superproperty
* @param boolean $sort_by_notation whether to sort the property values by their notation code
*/
- public function __construct($prop, $label, $tooltip=null, $super=null, $sort_by_notation=false)
+ public function __construct($model, $prop, $label, $tooltip=null, $super=null, $sort_by_notation=false)
{
+ $this->model = $model;
$this->prop = $prop;
$this->label = $label;
$this->tooltip = $tooltip;
@@ -47,7 +49,7 @@ public function getLabel()
// we don't maintain DC 1.1 translations separate from DC Terms
$prop = (substr($this->prop, 0, 5) == 'dc11:') ?
str_replace('dc11:', 'dc:', $this->prop) : $this->prop;
- $label = $this->getText($prop);
+ $label = $this->model>getText($prop);
if ($label != $prop) {
return $label;
}
@@ -78,7 +80,7 @@ public function getDescription()
$helpprop = $this->prop . "_help";
// see if we have a translation with the help text
- $help = $this->getText($helpprop);
+ $help = $this->model->getText($helpprop);
if ($help != $helpprop) {
return $help;
}
diff --git a/src/model/ConceptPropertyValue.php b/src/model/ConceptPropertyValue.php
index 4206f34ae..5aabc3258 100644
--- a/src/model/ConceptPropertyValue.php
+++ b/src/model/ConceptPropertyValue.php
@@ -165,11 +165,11 @@ public function getReifiedPropertyValues()
str_replace('dc11:', 'dc:', $prop) : $prop;
foreach ($this->resource->allLiterals($prop) as $val) {
if ($prop !== 'rdf:value') { // shown elsewhere
- $ret[gettext($propkey)] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $val, $prop);
+ $ret[$this->model->getText($propkey)] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $val, $prop);
}
}
foreach ($this->resource->allResources($prop) as $val) {
- $ret[gettext($propkey)] = new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang);
+ $ret[$this->model->getText($propkey)] = new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang);
}
}
return $ret;
diff --git a/src/model/DataObject.php b/src/model/DataObject.php
index dca42d356..d0a160448 100644
--- a/src/model/DataObject.php
+++ b/src/model/DataObject.php
@@ -140,16 +140,6 @@ public function getLang()
}
}
- /**
- * Get text translated in language set by SetLocale function
- *
- * @param string $text text to be translated
- */
- protected function getText($text)
- {
- return $this->model->getText($text);
- }
-
/**
* Getter function for retrieving the resource.
*/
diff --git a/src/model/Model.php b/src/model/Model.php
index 83f962d33..98c115677 100644
--- a/src/model/Model.php
+++ b/src/model/Model.php
@@ -150,7 +150,7 @@ public function getTypes($vocid = null, $lang = null)
if (empty($values)) {
$shorteneduri = EasyRdf\RdfNamespace::shorten($uri);
if ($shorteneduri !== null) {
- $this->translator->setlocale($lang);
+ if (isset($lang)) $this->translator->setlocale($lang);
$trans = $this->getText($shorteneduri);
if ($trans) {
$result[$uri] = array('label' => $trans);
diff --git a/src/model/VocabularyCategory.php b/src/model/VocabularyCategory.php
index 894d85991..b8f373a4a 100644
--- a/src/model/VocabularyCategory.php
+++ b/src/model/VocabularyCategory.php
@@ -36,7 +36,7 @@ public function getTitle()
$label = $this->resource->label($this->getLang());
return is_null($label) ? $this->resource->localName() : $label->getValue();
}
- return gettext('Vocabularies');
+ return $this->model->getText('Vocabularies');
}
}
diff --git a/tests/ConceptPropertyTest.php b/tests/ConceptPropertyTest.php
index cfcfca95c..3e15bbd80 100644
--- a/tests/ConceptPropertyTest.php
+++ b/tests/ConceptPropertyTest.php
@@ -22,7 +22,7 @@ protected function setUp(): void
*/
public function testGetConstructAndLabel()
{
- $prop = new ConceptProperty('skosmos:testLabel', 'Test label');
+ $prop = new ConceptProperty($this->model, 'skosmos:testLabel', 'Test label');
$this->assertEquals('Test label', $prop->getLabel());
}
@@ -62,7 +62,7 @@ public function testGetLabel()
*/
public function testGetLabelReturnsNullWhenThereIsNoLabel()
{
- $prop = new ConceptProperty('skosmos:type', null);
+ $prop = new ConceptProperty($this->model, 'skosmos:type', null);
$this->assertEquals(null, $prop->getLabel());
}
@@ -207,7 +207,7 @@ public function testGetPropertiesSubClassOfHiddenLabel()
*/
public function testGetIDShortenedURI()
{
- $prop = new ConceptProperty('skosmos:testLabel', 'Test label');
+ $prop = new ConceptProperty($this->model, 'skosmos:testLabel', 'Test label');
$this->assertEquals('skosmos_testLabel', $prop->getID());
}
@@ -216,7 +216,7 @@ public function testGetIDShortenedURI()
*/
public function testGetIDFullURI()
{
- $prop = new ConceptProperty('http://rdaregistry.info/Elements/a/P50008', 'has hierarchical superior');
+ $prop = new ConceptProperty($this->model, 'http://rdaregistry.info/Elements/a/P50008', 'has hierarchical superior');
$this->assertEquals('http___rdaregistry_info_Elements_a_P50008', $prop->getID());
}
diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php
index e2d50f9de..be573f037 100644
--- a/tests/ConceptPropertyValueLiteralTest.php
+++ b/tests/ConceptPropertyValueLiteralTest.php
@@ -221,6 +221,7 @@ public function testGetContainsHtml()
*/
public function testGetXlLabel()
{
+ $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$voc = $this->model->getVocabulary('xl');
$conc = $voc->getConceptInfo('http://www.skosmos.skos/xl/c1', 'en')[0];
$props = $conc->getProperties();
diff --git a/tests/ConceptTest.php b/tests/ConceptTest.php
index 92427e880..e96310eb7 100644
--- a/tests/ConceptTest.php
+++ b/tests/ConceptTest.php
@@ -459,6 +459,7 @@ public function testGetGroupPropertiesWithHierarchy()
*/
public function testGetPropertiesWithNarrowersPartOfACollection()
{
+ $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
$vocab = $model->getVocabulary('groups');
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/groups/ta1", "en");
diff --git a/tests/ModelTest.php b/tests/ModelTest.php
index 8c4188100..b889fad8a 100644
--- a/tests/ModelTest.php
+++ b/tests/ModelTest.php
@@ -623,4 +623,14 @@ public function testGetResourceLabelCorrectLanguage()
$this->assertEquals('testiarvo', $this->model->getResourceLabel($mockres, 'fi'));
}
+ /**
+ * @covers Model::getText
+ * @covers Model::setLocale
+ */
+ public function testGetText()
+ {
+ $this->model->setLocale('fi');
+ $this->assertEquals('Luotu', $this->model->getText('skosmos:created'));
+ }
+
}
From cec3cbc6edd754b798424ab47fdc7fe6e0fa28f2 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Tue, 29 Aug 2023 14:29:51 +0300
Subject: [PATCH 07/10] Fixed PHP styling
---
src/model/Model.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/model/Model.php b/src/model/Model.php
index 98c115677..74c909c62 100644
--- a/src/model/Model.php
+++ b/src/model/Model.php
@@ -150,7 +150,9 @@ public function getTypes($vocid = null, $lang = null)
if (empty($values)) {
$shorteneduri = EasyRdf\RdfNamespace::shorten($uri);
if ($shorteneduri !== null) {
- if (isset($lang)) $this->translator->setlocale($lang);
+ if (isset($lang)) {
+ $this->translator->setlocale($lang);
+ }
$trans = $this->getText($shorteneduri);
if ($trans) {
$result[$uri] = array('label' => $trans);
From e3e84f72de1c7cebc1a3f39ab358556ed6bf8850 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Tue, 29 Aug 2023 19:18:53 +0300
Subject: [PATCH 08/10] Removed functions used by gettext
---
src/model/ConceptProperty.php | 2 +-
tests/ConceptMappingPropertyValueTest.php | 7 -------
tests/ConceptPropertyTest.php | 7 -------
tests/ConceptPropertyValueLiteralTest.php | 7 -------
tests/ConceptPropertyValueTest.php | 7 -------
tests/ConceptTest.php | 7 -------
tests/Http304Test.php | 6 ------
tests/RequestTest.php | 7 -------
tests/RestControllerTest.php | 7 -------
9 files changed, 1 insertion(+), 56 deletions(-)
diff --git a/src/model/ConceptProperty.php b/src/model/ConceptProperty.php
index 64bae2c9b..2e6c28162 100644
--- a/src/model/ConceptProperty.php
+++ b/src/model/ConceptProperty.php
@@ -49,7 +49,7 @@ public function getLabel()
// we don't maintain DC 1.1 translations separate from DC Terms
$prop = (substr($this->prop, 0, 5) == 'dc11:') ?
str_replace('dc11:', 'dc:', $this->prop) : $this->prop;
- $label = $this->model>getText($prop);
+ $label = $this->model->getText($prop);
if ($label != $prop) {
return $label;
}
diff --git a/tests/ConceptMappingPropertyValueTest.php b/tests/ConceptMappingPropertyValueTest.php
index d7b644527..cbd234ab7 100644
--- a/tests/ConceptMappingPropertyValueTest.php
+++ b/tests/ConceptMappingPropertyValueTest.php
@@ -9,13 +9,6 @@ class ConceptMappingPropertyValueTest extends PHPUnit\Framework\TestCase
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$this->model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
$this->vocab = $this->model->getVocabulary('mapping');
$concepts = $this->vocab->getConceptInfo('http://www.skosmos.skos/mapping/m1', 'en');
diff --git a/tests/ConceptPropertyTest.php b/tests/ConceptPropertyTest.php
index 3e15bbd80..15ec933fe 100644
--- a/tests/ConceptPropertyTest.php
+++ b/tests/ConceptPropertyTest.php
@@ -6,13 +6,6 @@ class ConceptPropertyTest extends PHPUnit\Framework\TestCase
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$this->model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
}
diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php
index be573f037..467b65d51 100644
--- a/tests/ConceptPropertyValueLiteralTest.php
+++ b/tests/ConceptPropertyValueLiteralTest.php
@@ -8,13 +8,6 @@ class ConceptPropertyValueLiteralTest extends PHPUnit\Framework\TestCase
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$this->model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
$this->vocab = $this->model->getVocabulary('test');
$results = $this->vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
diff --git a/tests/ConceptPropertyValueTest.php b/tests/ConceptPropertyValueTest.php
index 0f03a5951..63dff15c8 100644
--- a/tests/ConceptPropertyValueTest.php
+++ b/tests/ConceptPropertyValueTest.php
@@ -8,13 +8,6 @@ class ConceptPropertyValueTest extends PHPUnit\Framework\TestCase
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$this->model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
$this->vocab = $this->model->getVocabulary('test');
$results = $this->vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
diff --git a/tests/ConceptTest.php b/tests/ConceptTest.php
index e96310eb7..6c9866b33 100644
--- a/tests/ConceptTest.php
+++ b/tests/ConceptTest.php
@@ -12,13 +12,6 @@ class ConceptTest extends PHPUnit\Framework\TestCase
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$this->model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
$this->vocab = $this->model->getVocabulary('test');
$results = $this->vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
diff --git a/tests/Http304Test.php b/tests/Http304Test.php
index fa3aaacab..773b6d76c 100644
--- a/tests/Http304Test.php
+++ b/tests/Http304Test.php
@@ -33,12 +33,6 @@ class Http304Test extends TestCase
*/
public function initObjects(string $vocabularyName)
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
$this->model = Mockery::mock(new Model(new GlobalConfig('/../../tests/testconfig.ttl')))->makePartial();
$this->vocab = Mockery::mock($this->model->getVocabulary($vocabularyName))->makePartial();
$this->controller = Mockery::mock('WebController')
diff --git a/tests/RequestTest.php b/tests/RequestTest.php
index 635ed63de..9eb502fa0 100644
--- a/tests/RequestTest.php
+++ b/tests/RequestTest.php
@@ -7,13 +7,6 @@ class RequestTest extends PHPUnit\Framework\TestCase
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$config = new GlobalConfig('/../../tests/testconfig.ttl');
$this->model = new Model($config);
$this->request = new Request($this->model);
diff --git a/tests/RestControllerTest.php b/tests/RestControllerTest.php
index 560698c64..91938f923 100644
--- a/tests/RestControllerTest.php
+++ b/tests/RestControllerTest.php
@@ -12,13 +12,6 @@ class RestControllerTest extends \PHPUnit\Framework\TestCase
private $controller;
protected function setUp(): void
{
- putenv("LANGUAGE=en_GB.utf8");
- putenv("LC_ALL=en_GB.utf8");
- setlocale(LC_ALL, 'en_GB.utf8');
- bindtextdomain('skosmos', 'resource/translations');
- bind_textdomain_codeset('skosmos', 'UTF-8');
- textdomain('skosmos');
-
$globalConfig = new GlobalConfig('/../../tests/testconfig.ttl');
$this->model = Mockery::mock(new Model($globalConfig));
$this->controller = new RestController($this->model);
From 48b31a51acb2fd8be2452c033e0cecd05d86c764 Mon Sep 17 00:00:00 2001
From: Vainonen <8686308+Vainonen@users.noreply.github.com>
Date: Wed, 30 Aug 2023 11:21:44 +0300
Subject: [PATCH 09/10] Removed test skips
---
src/controller/Controller.php | 6 +-----
src/controller/WebController.php | 5 -----
tests/ConceptMappingPropertyValueTest.php | 8 --------
tests/ConceptPropertyTest.php | 2 --
tests/ConceptPropertyValueLiteralTest.php | 4 ----
tests/ConceptPropertyValueTest.php | 1 -
tests/ConceptTest.php | 7 -------
tests/RestControllerTest.php | 1 -
8 files changed, 1 insertion(+), 33 deletions(-)
diff --git a/src/controller/Controller.php b/src/controller/Controller.php
index 233d55b0a..029ce140d 100644
--- a/src/controller/Controller.php
+++ b/src/controller/Controller.php
@@ -21,8 +21,6 @@ class Controller
protected $languages;
- protected $translator;
-
/**
* Initializes the Model object.
*/
@@ -37,9 +35,7 @@ public function __construct($model)
foreach ($this->model->getConfig()->getLanguages() as $langcode => $locale) {
$this->languages[$langcode] = array('locale' => $locale);
$this->model->setLocale($langcode);
- $this->translator = $this->model->getTranslator();
- $this->translator->setlocale($langcode);
- $this->languages[$langcode]['name'] = $this->translator->trans('in_this_language');
+ $this->languages[$langcode]['name'] = $this->model->getText('in_this_language');
$this->languages[$langcode]['lemma'] = Punic\Language::getName($langcode, $langcode);
}
}
diff --git a/src/controller/WebController.php b/src/controller/WebController.php
index fa00c682b..5608fe793 100644
--- a/src/controller/WebController.php
+++ b/src/controller/WebController.php
@@ -213,7 +213,6 @@ public function invokeVocabularyConcept(Request $request)
public function invokeFeedbackForm($request)
{
$template = $this->twig->loadTemplate('feedback.twig');
- //$this->setLanguageProperties($request->getLang());
$this->model->setLocale($request->getLang());
$vocabList = $this->model->getVocabularyList(false);
$vocab = $request->getVocab();
@@ -322,7 +321,6 @@ public function sendFeedback($request, $message, $messageSubject, $fromName = nu
public function invokeAboutPage($request)
{
$template = $this->twig->loadTemplate('about.twig');
- //$this->setLanguageProperties($request->getLang());
$this->model->setLocale($request->getLang());
$url = $request->getServerConstant('HTTP_HOST');
@@ -342,7 +340,6 @@ public function invokeGlobalSearch($request)
{
$lang = $request->getLang();
$template = $this->twig->loadTemplate('global-search.twig');
- //$this->setLanguageProperties($lang);
$this->model->setLocale($request->getLang());
$parameters = new ConceptSearchParameters($request, $this->model->getConfig());
@@ -412,7 +409,6 @@ public function invokeGlobalSearch($request)
public function invokeVocabularySearch($request)
{
$template = $this->twig->loadTemplate('vocab-search.twig');
- //$this->setLanguageProperties($request->getLang());
$this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
$searchResults = null;
@@ -518,7 +514,6 @@ public function invokeVocabularyHome($request)
*/
public function invokeGenericErrorPage($request, $message = null)
{
- //$this->setLanguageProperties($request->getLang());
$this->model->setLocale($request->getLang());
header("HTTP/1.0 404 Not Found");
$template = $this->twig->loadTemplate('error.twig');
diff --git a/tests/ConceptMappingPropertyValueTest.php b/tests/ConceptMappingPropertyValueTest.php
index cbd234ab7..4eefdd3b6 100644
--- a/tests/ConceptMappingPropertyValueTest.php
+++ b/tests/ConceptMappingPropertyValueTest.php
@@ -34,7 +34,6 @@ public function testConstructor()
*/
public function testGetLabelFromExternalVocabulary()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals('Eel', $propvals['Eel http://www.skosmos.skos/test/ta115']->getLabel()->getValue());
}
@@ -128,7 +127,6 @@ public function testGetNotation()
*/
public function testGetExVocab()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertInstanceOf('Vocabulary', $propvals['Eel http://www.skosmos.skos/test/ta115']->getExVocab());
$this->assertEquals('test', $propvals['Eel http://www.skosmos.skos/test/ta115']->getExVocab()->getId());
@@ -139,7 +137,6 @@ public function testGetExVocab()
*/
public function testGetVocabNameWithExternalVocabulary()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals('Test ontology', $propvals['Eel http://www.skosmos.skos/test/ta115']->getVocabName());
}
@@ -149,7 +146,6 @@ public function testGetVocabNameWithExternalVocabulary()
*/
public function testGetUri()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals('http://www.skosmos.skos/test/ta115', $propvals['Eel http://www.skosmos.skos/test/ta115']->getUri());
}
@@ -159,7 +155,6 @@ public function testGetUri()
*/
public function testGetVocab()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals($this->vocab, $propvals['Eel http://www.skosmos.skos/test/ta115']->getVocab());
}
@@ -169,7 +164,6 @@ public function testGetVocab()
*/
public function testGetType()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals('skos:exactMatch', $propvals['Eel http://www.skosmos.skos/test/ta115']->getType());
}
@@ -179,7 +173,6 @@ public function testGetType()
*/
public function testToString()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals('Eel', $propvals['Eel http://www.skosmos.skos/test/ta115']->__toString());
}
@@ -189,7 +182,6 @@ public function testToString()
*/
public function testAsJskos()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals([
'type' => [
diff --git a/tests/ConceptPropertyTest.php b/tests/ConceptPropertyTest.php
index 15ec933fe..232f84b83 100644
--- a/tests/ConceptPropertyTest.php
+++ b/tests/ConceptPropertyTest.php
@@ -27,7 +27,6 @@ public function testGetConstructAndLabel()
*/
public function testGetDescriptionAndLabel()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta122', 'en');
$concept = $concepts[0];
@@ -95,7 +94,6 @@ public function testGetDescriptionAndLabelForCustomPropertyMissingDesc()
*/
public function testGetType()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta122', 'en');
$concept = $concepts[0];
diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php
index 467b65d51..3960bc1f4 100644
--- a/tests/ConceptPropertyValueLiteralTest.php
+++ b/tests/ConceptPropertyValueLiteralTest.php
@@ -64,7 +64,6 @@ public function testGetLabelThatIsABrokenDate()
*/
public function testGetLabelForDatatype()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
$props = $concepts[0]->getProperties();
@@ -77,7 +76,6 @@ public function testGetLabelForDatatype()
*/
public function testGetNotationDatatypeWithoutLabel()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta128', 'en');
$props = $concepts[0]->getProperties();
@@ -90,7 +88,6 @@ public function testGetNotationDatatypeWithoutLabel()
*/
public function testGetLabelForDatatypeIfNull()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta126', 'en');
$props = $concepts[0]->getProperties();
@@ -214,7 +211,6 @@ public function testGetContainsHtml()
*/
public function testGetXlLabel()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$voc = $this->model->getVocabulary('xl');
$conc = $voc->getConceptInfo('http://www.skosmos.skos/xl/c1', 'en')[0];
$props = $conc->getProperties();
diff --git a/tests/ConceptPropertyValueTest.php b/tests/ConceptPropertyValueTest.php
index 63dff15c8..020dd33cd 100644
--- a/tests/ConceptPropertyValueTest.php
+++ b/tests/ConceptPropertyValueTest.php
@@ -176,7 +176,6 @@ public function testGetSubMembersEmpty()
public function testGetReifiedPropertyValues()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('xl');
$concept = $vocab->getConceptInfo('http://www.skosmos.skos/xl/c1', 'en')[0];
$props = $concept->getProperties();
diff --git a/tests/ConceptTest.php b/tests/ConceptTest.php
index 6c9866b33..5921ea9ff 100644
--- a/tests/ConceptTest.php
+++ b/tests/ConceptTest.php
@@ -167,7 +167,6 @@ public function testGetPropertiesLiteralValue()
*/
public function testGetPropertiesCorrectNumberOfProperties()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$props = $this->concept->getProperties();
$this->assertEquals(9, sizeof($props));
@@ -182,7 +181,6 @@ public function testGetPropertiesCorrectNumberOfProperties()
*/
public function testGetPropertiesCorrectOrderOfProperties()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$props = $this->concept->getProperties();
$expected = array(0 => 'rdf:type', 1 => 'skos:broader', 2 => 'skos:narrower', 3 => 'skos:altLabel',
4 => 'skos:scopeNote', 5 => 'http://www.skosmos.skos/multiLingOff', 6 => 'http://www.skosmos.skos/multiLingOn',
@@ -217,7 +215,6 @@ public function testGetPropertiesAlphabeticalSortingOfPropertyValues()
*/
public function testGetMappingPropertiesWithIdenticalLabels()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('duplicates');
$concepts = $vocab->getConceptInfo("http://www.skosmos.skos/dup/d3", "en");
$concept = $concepts[0];
@@ -340,7 +337,6 @@ public function testGetTimestampInvalidResult()
*/
public function testGetPropertiesTypes()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$props = $this->concept->getProperties();
$propvals = $props['rdf:type']->getValues();
$this->assertCount(1, $propvals); // should only have type meta:TestClass, not skos:Concept (see #200)
@@ -452,7 +448,6 @@ public function testGetGroupPropertiesWithHierarchy()
*/
public function testGetPropertiesWithNarrowersPartOfACollection()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$model = new Model(new GlobalConfig('/../../tests/testconfig.ttl'));
$vocab = $model->getVocabulary('groups');
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/groups/ta1", "en");
@@ -549,7 +544,6 @@ public function testMultilingualPropertiesOffWithoutLangHit()
*/
public function testGetPropertiesDefinitionLiteral()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta115', 'en');
$concept = $concepts[0];
@@ -564,7 +558,6 @@ public function testGetPropertiesDefinitionLiteral()
*/
public function testGetPropertiesDefinitionResource()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta122', 'en');
$concept = $concepts[0];
diff --git a/tests/RestControllerTest.php b/tests/RestControllerTest.php
index 91938f923..b6a2bb87a 100644
--- a/tests/RestControllerTest.php
+++ b/tests/RestControllerTest.php
@@ -890,7 +890,6 @@ public function testDeprecatedChanges()
*/
public function testVocabularyStatistics()
{
- $this->markTestSkipped('disabled since the functionality needs to be reimplemented after the new translation component is in use');
$request = new Request($this->model);
$request->setQueryParam('format', 'application/json');
$request->setVocab('test');
From fff56d0337e51f5fd103b9f7b9fb57b19eff4e0a Mon Sep 17 00:00:00 2001
From: Osma Suominen
Date: Wed, 30 Aug 2023 12:38:40 +0300
Subject: [PATCH 10/10] fix fragile test that depended on current locale
---
tests/ConceptTest.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/ConceptTest.php b/tests/ConceptTest.php
index 5921ea9ff..f85cbcae0 100644
--- a/tests/ConceptTest.php
+++ b/tests/ConceptTest.php
@@ -110,6 +110,9 @@ public function testSetFoundBy()
*/
public function testGetForeignLabels()
{
+ # make sure UK English collation is being used as the default
+ setlocale(LC_ALL, "en_GB.utf8");
+
$labels = $this->concept->getForeignLabels();
$this->assertEquals('Karppi', $labels['Finnish']['prefLabel'][0]->getLabel());