Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jul 5, 2021
1 parent bfb0cf6 commit 3ad4a00
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
18 changes: 16 additions & 2 deletions core-bundle/src/Migration/Version412/PageLanguageMigration.php
Expand Up @@ -46,14 +46,28 @@ public function shouldRun(): bool
return false;
}

$count = $this->connection->fetchOne("SELECT COUNT(*) FROM tl_page WHERE type='root' AND SUBSTRING(language, 3, 1) = '-'");
$count = $this->connection->fetchOne("
SELECT
COUNT(*)
FROM
tl_page
WHERE
type='root' AND SUBSTRING(language, 3, 1) = '-'
");

return $count > 0;
}

public function run(): MigrationResult
{
$pages = $this->connection->fetchAllAssociative("SELECT id, language FROM tl_page WHERE type='root' AND SUBSTRING(language, 3, 1) = '-'");
$pages = $this->connection->fetchAllAssociative("
SELECT
id, language
FROM
tl_page
WHERE
type='root' AND SUBSTRING(language, 3, 1) = '-'
");

foreach ($pages as $page) {
$this->connection->update(
Expand Down
4 changes: 2 additions & 2 deletions core-bundle/src/Resources/contao/dca/tl_page.php
Expand Up @@ -260,11 +260,11 @@
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>64, 'nospace'=>true, 'decodeEntities'=>true, 'doNotCopy'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(64) NOT NULL default ''",
'save_callback' => array
'save_callback' => array
(
static function ($value)
{
// Make sure it's at least a basic language
// Make sure there is at least a basic language
if (!preg_match('/^[a-z]{2,}/i', $value)) {
throw new \RuntimeException($GLOBALS['TL_LANG']['ERR']['language']);
}
Expand Down
Expand Up @@ -616,7 +616,7 @@ protected function doReplace($strBuffer, $blnCache)
// Check if there are wildcards (see #8313)
foreach ($langs as $k=>$v)
{
if (substr($v, -1) === '*')
if (substr($v, -1) == '*')
{
$langs[$k] = LocaleUtil::formatAsLocale(substr($v, 0, -1));

Expand All @@ -635,7 +635,7 @@ protected function doReplace($strBuffer, $blnCache)
{
for (; $_rit<$_cnt; $_rit+=2)
{
if ($tags[$_rit+1] === 'iflng' || (strncmp($tags[$_rit+1], 'iflng::', 7) && LocaleUtil::formatAsLocale(substr($tags[$_rit+1], 7)) === $pageLanguage))
if ($tags[$_rit+1] == 'iflng' || (strncmp($tags[$_rit+1], 'iflng::', 7) && LocaleUtil::formatAsLocale(substr($tags[$_rit+1], 7)) == $pageLanguage))
{
break;
}
Expand Down
16 changes: 9 additions & 7 deletions core-bundle/src/Util/LocaleUtil.php
Expand Up @@ -13,7 +13,7 @@
namespace Contao\CoreBundle\Util;

/**
* The LocaleUtil helps in handling ICU Locale IDs and IETF Language Tags (BCP 47).
* The LocaleUtil class helps in handling ICU Locale IDs and IETF Language Tags (BCP 47).
* Both are almost identical, Locale ID uses underline (_) and Language Tag uses dash (-).
*
* For any method, we are safely assuming the input can be any format, therefore we try
Expand All @@ -39,8 +39,8 @@ public static function getPrimaryLanguage(string $locale): string
}

/**
* Generates an ordered list of locales according to ICU rules,
* the last array item is the most specific locale.
* Generates an ordered list of locales according to ICU rules, the last
* array item is the most specific locale.
*
* This can also be used to load languages files that override each other.
* A script tag (e.g. chinese traditional) always overrides a region.
Expand Down Expand Up @@ -75,7 +75,8 @@ public static function getFallbacks(string $locale): array
}

/**
* Converts an Locale ID (_) to a Language Tag (-) and strips keywords after the @ sign.
* Converts an Locale ID (_) to a Language Tag (-) and strips keywords
* after the @ sign.
*
* Language Tag is used in two cases in Contao:
* 1. The XML/HTML lang attribute.
Expand All @@ -88,10 +89,11 @@ public static function formatAsLanguageTag(string $localeId): string
}

/**
* Converts a Language Tag (-) to a Locale ID (_) and strips keywords after the @ sign.
* Converts a Language Tag (-) to a Locale ID (_) and strips keywords
* after the @ sign.
*
* For historical reasons, the page language can be a Language Tag, so we need to safely-convert
* the value before looking up language files etc.
* For historical reasons, the page language can be a Language Tag, so we
* need to safely-convert the value before looking up language files etc.
*/
public static function formatAsLocale(string $languageTag): string
{
Expand Down

0 comments on commit 3ad4a00

Please sign in to comment.