Skip to content

Commit 0ef15f9

Browse files
Merge pull request #1377 from nextcloud/improve-finish-l10n
Change language code from fi_FI to fi
2 parents 5d4cc4a + ba472f7 commit 0ef15f9

File tree

6 files changed

+230
-1
lines changed

6 files changed

+230
-1
lines changed

l10n/.tx/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[main]
22
host = https://www.transifex.com
3-
lang_map = ja_JP: ja
3+
lang_map = bg_BG: bg, cs_CZ: cs, fi_FI: fi, hu_HU: hu, nb_NO: nb, sk_SK: sk, th_TH: th, ja_JP: ja
44

55
[nextcloud.core]
66
file_filter = <lang>/core.po

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@
686686
'OC\\Repair\\NC11\\FixMountStorages' => $baseDir . '/lib/private/Repair/NC11/FixMountStorages.php',
687687
'OC\\Repair\\NC11\\MoveAvatars' => $baseDir . '/lib/private/Repair/NC11/MoveAvatars.php',
688688
'OC\\Repair\\NC11\\MoveAvatarsBackgroundJob' => $baseDir . '/lib/private/Repair/NC11/MoveAvatarsBackgroundJob.php',
689+
'OC\\Repair\\NC12\\UpdateLanguageCodes' => $baseDir . '/lib/private/Repair/NC12/UpdateLanguageCodes.php',
689690
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
690691
'OC\\Repair\\RemoveRootShares' => $baseDir . '/lib/private/Repair/RemoveRootShares.php',
691692
'OC\\Repair\\RepairInvalidShares' => $baseDir . '/lib/private/Repair/RepairInvalidShares.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
716716
'OC\\Repair\\NC11\\FixMountStorages' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/FixMountStorages.php',
717717
'OC\\Repair\\NC11\\MoveAvatars' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/MoveAvatars.php',
718718
'OC\\Repair\\NC11\\MoveAvatarsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/MoveAvatarsBackgroundJob.php',
719+
'OC\\Repair\\NC12\\UpdateLanguageCodes' => __DIR__ . '/../../..' . '/lib/private/Repair/NC12/UpdateLanguageCodes.php',
719720
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
720721
'OC\\Repair\\RemoveRootShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveRootShares.php',
721722
'OC\\Repair\\RepairInvalidShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RepairInvalidShares.php',

lib/private/Repair.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OC\Repair\NC11\CleanPreviews;
3737
use OC\Repair\NC11\FixMountStorages;
3838
use OC\Repair\NC11\MoveAvatars;
39+
use OC\Repair\NC12\UpdateLanguageCodes;
3940
use OC\Repair\OldGroupMembershipShares;
4041
use OC\Repair\RemoveRootShares;
4142
use OC\Repair\SqliteAutoincrement;
@@ -134,6 +135,7 @@ public static function getRepairSteps() {
134135
\OC::$server->getConfig()
135136
),
136137
new FixMountStorages(\OC::$server->getDatabaseConnection()),
138+
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection()),
137139
];
138140
}
139141

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
4+
*
5+
* @author Morris Jobke <hey@morrisjobke.de>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OC\Repair\NC12;
25+
26+
use OCP\IDBConnection;
27+
use OCP\Migration\IOutput;
28+
use OCP\Migration\IRepairStep;
29+
30+
class UpdateLanguageCodes implements IRepairStep {
31+
/** @var IDBConnection */
32+
private $connection;
33+
34+
/**
35+
* @param IDBConnection $db
36+
*/
37+
public function __construct(IDBConnection $connection) {
38+
$this->connection = $connection;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function getName() {
45+
return 'Repair language codes';
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function run(IOutput $output) {
52+
$languages = [
53+
'bg_BG' => 'bg',
54+
'cs_CZ' => 'cs',
55+
'fi_FI' => 'fi',
56+
'hu_HU' => 'hu',
57+
'nb_NO' => 'nb',
58+
'sk_SK' => 'sk',
59+
'th_TH' => 'th',
60+
];
61+
62+
foreach ($languages as $oldCode => $newCode) {
63+
$qb = $this->connection->getQueryBuilder();
64+
65+
$affectedRows = $qb->update('preferences')
66+
->set('configvalue', $qb->createNamedParameter($newCode))
67+
->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
68+
->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
69+
->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode)))
70+
->execute();
71+
72+
$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
73+
}
74+
}
75+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
4+
*
5+
* @author Morris Jobke <hey@morrisjobke.de>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace Test\Repair\NC12;
25+
26+
use OC\Repair\NC12\UpdateLanguageCodes;
27+
use OCP\Migration\IOutput;
28+
use Test\TestCase;
29+
30+
/**
31+
* Class UpdateLanguageCodesTest
32+
*
33+
* @group DB
34+
*
35+
* @package Test\Repair
36+
*/
37+
class UpdateLanguageCodesTest extends TestCase {
38+
/** @var \OCP\IDBConnection */
39+
protected $connection;
40+
41+
protected function setUp() {
42+
parent::setUp();
43+
44+
$this->connection = \OC::$server->getDatabaseConnection();
45+
}
46+
47+
public function testRun() {
48+
49+
$users = [
50+
['userid' => 'user1', 'configvalue' => 'fi_FI'],
51+
['userid' => 'user2', 'configvalue' => 'de'],
52+
['userid' => 'user3', 'configvalue' => 'fi'],
53+
['userid' => 'user4', 'configvalue' => 'ja'],
54+
['userid' => 'user5', 'configvalue' => 'bg_BG'],
55+
['userid' => 'user6', 'configvalue' => 'ja'],
56+
['userid' => 'user7', 'configvalue' => 'th_TH'],
57+
['userid' => 'user8', 'configvalue' => 'th_TH'],
58+
];
59+
60+
// insert test data
61+
$qb = $this->connection->getQueryBuilder();
62+
$qb->insert('preferences')
63+
->values([
64+
'userid' => $qb->createParameter('userid'),
65+
'appid' => $qb->createParameter('appid'),
66+
'configkey' => $qb->createParameter('configkey'),
67+
'configvalue' => $qb->createParameter('configvalue'),
68+
]);
69+
foreach ($users as $user) {
70+
$qb->setParameters([
71+
'userid' => $user['userid'],
72+
'appid' => 'core',
73+
'configkey' => 'lang',
74+
'configvalue' => $user['configvalue'],
75+
])->execute();
76+
}
77+
78+
// check if test data is written to DB
79+
$qb = $this->connection->getQueryBuilder();
80+
$result = $qb->select(['userid', 'configvalue'])
81+
->from('preferences')
82+
->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
83+
->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
84+
->execute();
85+
86+
$rows = $result->fetchAll();
87+
$result->closeCursor();
88+
89+
$this->assertSame($users, $rows, 'Asserts that the entries are the ones from the test data set');
90+
91+
/** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */
92+
$outputMock = $this->createMock(IOutput::class);
93+
$outputMock->expects($this->at(0))
94+
->method('info')
95+
->with('Changed 1 setting(s) from "bg_BG" to "bg" in preferences table.');
96+
$outputMock->expects($this->at(1))
97+
->method('info')
98+
->with('Changed 0 setting(s) from "cs_CZ" to "cs" in preferences table.');
99+
$outputMock->expects($this->at(2))
100+
->method('info')
101+
->with('Changed 1 setting(s) from "fi_FI" to "fi" in preferences table.');
102+
$outputMock->expects($this->at(3))
103+
->method('info')
104+
->with('Changed 0 setting(s) from "hu_HU" to "hu" in preferences table.');
105+
$outputMock->expects($this->at(4))
106+
->method('info')
107+
->with('Changed 0 setting(s) from "nb_NO" to "nb" in preferences table.');
108+
$outputMock->expects($this->at(5))
109+
->method('info')
110+
->with('Changed 0 setting(s) from "sk_SK" to "sk" in preferences table.');
111+
$outputMock->expects($this->at(6))
112+
->method('info')
113+
->with('Changed 2 setting(s) from "th_TH" to "th" in preferences table.');
114+
115+
// run repair step
116+
$repair = new UpdateLanguageCodes($this->connection);
117+
$repair->run($outputMock);
118+
119+
// check if test data is correctly modified in DB
120+
$qb = $this->connection->getQueryBuilder();
121+
$result = $qb->select(['userid', 'configvalue'])
122+
->from('preferences')
123+
->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
124+
->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
125+
->orderBy('userid')
126+
->execute();
127+
128+
$rows = $result->fetchAll();
129+
$result->closeCursor();
130+
131+
// value has changed for one user
132+
$users[0]['configvalue'] = 'fi';
133+
$users[4]['configvalue'] = 'bg';
134+
$users[6]['configvalue'] = 'th';
135+
$users[7]['configvalue'] = 'th';
136+
$this->assertSame($users, $rows, 'Asserts that the entries are updated correctly.');
137+
138+
// remove test data
139+
foreach ($users as $user) {
140+
$qb = $this->connection->getQueryBuilder();
141+
$qb->delete('preferences')
142+
->where($qb->expr()->eq('userid', $qb->createNamedParameter($user['userid'])))
143+
->andWhere($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
144+
->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
145+
->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($user['configvalue'])))
146+
->execute();
147+
}
148+
}
149+
150+
}

0 commit comments

Comments
 (0)