Skip to content

Commit c997183

Browse files
authored
Merge pull request #315 from VSEphpbb/lang-iso
Convert language from using ID nums to ISO names
2 parents 57668ed + c108057 commit c997183

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+491
-120
lines changed

acp/boardrules_module.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public function main($id, $mode)
2626
/** @var \phpbb\request\request $request */
2727
$request = $phpbb_container->get('request');
2828

29+
/** @var \phpbb\boardrules\controller\admin_controller $admin_controller */
30+
$admin_controller = $phpbb_container->get('phpbb.boardrules.admin.controller');
31+
2932
// Add the board rules ACP lang file
3033
$lang->add_lang('boardrules_acp', 'phpbb/boardrules');
3134

32-
// Get an instance of the admin controller
33-
$admin_controller = $phpbb_container->get('phpbb.boardrules.admin.controller');
34-
3535
// Requests
3636
$action = $request->variable('action', '');
37-
$language = $request->variable('language', 0);
37+
$language = $request->variable('language', '');
3838
$parent_id = $request->variable('parent_id', 0);
3939
$rule_id = $request->variable('rule_id', 0);
4040

adm/style/boardrules_manage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ <h1>{L_ACP_BOARDRULES_MANAGE}</h1>
111111
<dd>
112112
<select name="language" id="language">
113113
<!-- BEGIN options -->
114-
<option value="{options.LANG_ID}"<!-- IF options.S_LANG_DEFAULT --> selected="selected"<!-- ENDIF -->>{options.LANG_LOCAL_NAME}</option>
114+
<option value="{options.LANG_ISO}"<!-- IF options.S_LANG_DEFAULT --> selected="selected"<!-- ENDIF -->>{options.LANG_LOCAL_NAME}</option>
115115
<!-- END options -->
116116
</select>
117117
<input type="submit" value="{L_GO}" class="button2">

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "An extension which allows you to create a set of rules for your phpBB forum",
55
"homepage": "https://www.phpbb.com",
6-
"version": "2.0.1-dev",
6+
"version": "2.1.0-dev",
77
"keywords": ["phpbb", "extension", "rules"],
88
"license": "GPL-2.0",
99
"authors": [

controller/admin_controller.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected function set_options()
181181
public function display_language_selection()
182182
{
183183
// Check if there are any available languages
184-
$sql = 'SELECT lang_id, lang_iso, lang_local_name
184+
$sql = 'SELECT lang_iso, lang_local_name
185185
FROM ' . LANG_TABLE . '
186186
ORDER BY lang_english_name';
187187
$result = $this->db->sql_query($sql);
@@ -196,7 +196,7 @@ public function display_language_selection()
196196
$this->template->assign_block_vars('options', array(
197197
'S_LANG_DEFAULT' => $row['lang_iso'] == $this->config['default_lang'],
198198

199-
'LANG_ID' => $row['lang_id'],
199+
'LANG_ISO' => $row['lang_iso'],
200200
'LANG_LOCAL_NAME' => $row['lang_local_name'],
201201
));
202202
}
@@ -208,20 +208,20 @@ public function display_language_selection()
208208
{
209209
// If there is only one available language its index is 0
210210
// and that language is the default board language.
211-
// We do not need any loops here to get its id.
212-
$this->display_rules($rows[0]['lang_id']);
211+
// We do not need any loops here to get its iso code.
212+
$this->display_rules($rows[0]['lang_iso']);
213213
}
214214
}
215215

216216
/**
217217
* Display the rules
218218
*
219-
* @param int $language Language selection identifier; default: 0
219+
* @param string $language Language selection iso
220220
* @param int $parent_id Category to display rules from; default: 0
221221
* @return void
222222
* @access public
223223
*/
224-
public function display_rules($language = 0, $parent_id = 0)
224+
public function display_rules($language, $parent_id = 0)
225225
{
226226
// Grab all the rules in the current user's language
227227
$entities = $this->rule_operator->get_rules($language, $parent_id);
@@ -282,12 +282,12 @@ public function display_rules($language = 0, $parent_id = 0)
282282
/**
283283
* Add a rule
284284
*
285-
* @param int $language Language selection identifier; default: 0
285+
* @param string $language Language selection iso
286286
* @param int $parent_id Category to display rules from; default: 0
287287
* @return void
288288
* @access public
289289
*/
290-
public function add_rule($language = 0, $parent_id = 0)
290+
public function add_rule($language, $parent_id = 0)
291291
{
292292
// Add form key
293293
add_form_key('add_edit_rule');

controller/admin_interface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ public function display_language_selection();
3939
/**
4040
* Display the rules
4141
*
42-
* @param int $language Language selection identifier; default: 0
42+
* @param string $language Language selection iso
4343
* @param int $parent_id Category to display rules from; default: 0
4444
* @return void
4545
* @access public
4646
*/
47-
public function display_rules($language = 0, $parent_id = 0);
47+
public function display_rules($language, $parent_id = 0);
4848

4949
/**
5050
* Add a rule
5151
*
52-
* @param int $language Language selection identifier; default: 0
52+
* @param string $language Language selection iso
5353
* @param int $parent_id Category to display rules from; default: 0
5454
* @return void
5555
* @access public
5656
*/
57-
public function add_rule($language = 0, $parent_id = 0);
57+
public function add_rule($language, $parent_id = 0);
5858

5959
/**
6060
* Edit a rule

controller/main_controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function display()
8787
$rule_counter = 'a'; // Alpha counter used for rules
8888

8989
// Grab all the rules in the current user's language
90-
$entities = $this->rule_operator->get_rules($this->user->get_iso_lang_id());
90+
$entities = $this->rule_operator->get_rules($this->lang->get_used_language());
9191

9292
/* @var $entity \phpbb\boardrules\entity\rule */
9393
foreach ($entities as $entity)

entity/rule.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function import($data)
105105
$fields = array(
106106
// column => data type (see settype())
107107
'rule_id' => 'integer',
108-
'rule_language' => 'integer',
108+
'rule_language' => 'string',
109109
'rule_left_id' => 'integer',
110110
'rule_right_id' => 'integer',
111111
'rule_parent_id' => 'integer',
@@ -149,9 +149,9 @@ public function import($data)
149149
// Some fields must be unsigned (>= 0)
150150
$validate_unsigned = array(
151151
'rule_id',
152-
'rule_language',
153152
'rule_left_id',
154153
'rule_right_id',
154+
'rule_parent_id',
155155
'rule_message_bbcode_options',
156156
);
157157

@@ -172,12 +172,12 @@ public function import($data)
172172
*
173173
* Will throw an exception if the rule was already inserted (call save() instead)
174174
*
175-
* @param int $language The language identifier
175+
* @param string $language The language iso
176176
* @return rule_interface $this object for chaining calls; load()->set()->save()
177177
* @access public
178178
* @throws \phpbb\boardrules\exception\out_of_bounds
179179
*/
180-
public function insert($language = 0)
180+
public function insert($language)
181181
{
182182
if (!empty($this->data['rule_id']))
183183
{
@@ -501,7 +501,7 @@ public function set_anchor($anchor)
501501
FROM ' . $this->boardrules_table . "
502502
WHERE rule_anchor = '" . $this->db->sql_escape($anchor) . "'
503503
AND rule_id <> " . $this->get_id() .
504-
($this->get_language() ? ' AND rule_language = ' . $this->get_language() : '');
504+
($this->get_language() ? " AND rule_language = '" . $this->get_language() . "'" : '');
505505
$result = $this->db->sql_query_limit($sql, 1);
506506
$row = $this->db->sql_fetchrow($result);
507507
$this->db->sql_freeresult($result);
@@ -519,28 +519,45 @@ public function set_anchor($anchor)
519519
}
520520

521521
/**
522-
* Get the language identifier
522+
* Get the language iso
523523
*
524-
* @return int language identifier
524+
* @return string language iso
525525
* @access public
526526
*/
527527
public function get_language()
528528
{
529-
return isset($this->data['rule_language']) ? (int) $this->data['rule_language'] : 0;
529+
return isset($this->data['rule_language']) ? $this->data['rule_language'] : '';
530530
}
531531

532532
/**
533-
* Set the language identifier
533+
* Set the language iso
534534
*
535-
* @param int $language language identifier
535+
* @param string $language language iso
536536
* @return rule_interface $this object for chaining calls; load()->set()->save()
537537
* @access public
538+
* @throws \phpbb\boardrules\exception\unexpected_value
538539
*/
539540
public function set_language($language)
540541
{
541542
if (!isset($this->data['rule_language']))
542543
{
543-
$this->data['rule_language'] = (int) $language;
544+
// Validate the requested language ISO is installed
545+
if ($language !== '')
546+
{
547+
$sql = 'SELECT lang_id
548+
FROM ' . LANG_TABLE . "
549+
WHERE lang_iso = '" . $this->db->sql_escape($language) . "'";
550+
$result = $this->db->sql_query($sql);
551+
$lang_id = $this->db->sql_fetchfield('lang_id');
552+
$this->db->sql_freeresult($result);
553+
554+
if (!$lang_id)
555+
{
556+
throw new \phpbb\boardrules\exception\unexpected_value(array('rule_language', 'WRONG_DATA_LANG', 'UNEXPECTED_VALUE'));
557+
}
558+
}
559+
560+
$this->data['rule_language'] = $language;
544561
}
545562

546563
return $this;

entity/rule_interface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public function import($data);
4646
*
4747
* Will throw an exception if the rule was already inserted (call save() instead)
4848
*
49-
* @param int $language The language identifier
49+
* @param string $language The language iso
5050
* @return rule_interface $this object for chaining calls; load()->set()->save()
5151
* @access public
5252
* @throws \phpbb\boardrules\exception\out_of_bounds
5353
*/
54-
public function insert($language = 0);
54+
public function insert($language);
5555

5656
/**
5757
* Save the current settings to the database
@@ -208,17 +208,17 @@ public function get_anchor();
208208
public function set_anchor($anchor);
209209

210210
/**
211-
* Get the language identifier
211+
* Get the language iso
212212
*
213-
* @return int language identifier
213+
* @return string language iso
214214
* @access public
215215
*/
216216
public function get_language();
217217

218218
/**
219-
* Set the language identifier
219+
* Set the language iso
220220
*
221-
* @param int $language language identifier
221+
* @param string $language language iso
222222
* @return rule_interface $this object for chaining calls; load()->set()->save()
223223
* @access public
224224
*/

language/ar/exceptions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@
5656
'EXCEPTION_NOT_UNIQUE' => 'البيانات المُدخلة موجودة مُسبقاً.',
5757
'EXCEPTION_UNEXPECTED_VALUE' => 'هناك خطأ في البيانات المُدخلة في الحقل `%1$s`. السبب : %2$s',
5858
'EXCEPTION_ILLEGAL_CHARACTERS' => 'البيانات التي أدخلتها تحتوي على حروف غير مقبولة.',
59+
60+
// Translators: do not change this
61+
'EXCEPTION_WRONG_DATA_LANG' => $lang['WRONG_DATA_LANG'],
5962
));

language/bg/exceptions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@
5555
'EXCEPTION_NOT_UNIQUE' => 'Въведеното не съответства.',
5656
'EXCEPTION_UNEXPECTED_VALUE' => 'Полето `%1$s` получава неочаквани данни. Причина: %2$s',
5757
'EXCEPTION_ILLEGAL_CHARACTERS' => 'Въведенот съдържа непозволени знаци.',
58+
59+
// Translators: do not change this
60+
'EXCEPTION_WRONG_DATA_LANG' => $lang['WRONG_DATA_LANG'],
5861
));

0 commit comments

Comments
 (0)