installation language construction

This commit is contained in:
John Bintz 2009-08-14 07:03:58 -04:00
parent ce753acf20
commit 8b270bb1ed
3 changed files with 55 additions and 10 deletions

View File

@ -111,12 +111,35 @@ class WhatDidTheySayAdmin {
} }
function install() { function install() {
$this->read_language_file();
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
if (empty($options)) { if (empty($options)) {
$this->default_options['languages'] = $this->build_default_languages();
update_option('what-did-they-say-options', $this->default_options); update_option('what-did-they-say-options', $this->default_options);
} }
} }
function build_default_languages() {
$full_default_language_info = array();
foreach ($this->default_options['languages'] as $info) {
$code = null;
if (is_string($info)) {
$code = $info;
$default = false;
}
if (is_array($info)) {
extract($info);
}
if (isset($this->all_languages[$code])) {
$full_default_language_info[$code] = array('name' => $this->all_languages[$code]);
if (!empty($default)) {
$full_default_language_info[$code]['default'] = true;
}
}
}
return $full_default_language_info;
}
function admin_menu() { function admin_menu() {
add_submenu_page( add_submenu_page(
'edit-comments.php', 'edit-comments.php',

View File

@ -6,16 +6,15 @@
<h3>Languages</h3> <h3>Languages</h3>
<ul id="language-holder"> <ul id="language-holder">
<?php foreach ($options['languages'] as $language) { <?php foreach ($options['languages'] as $code => $info) {
$default = false; $default = isset($info['default']);
if (is_array($language)) { $name = $info['name'];
$default = $language['default'];
$code = $language['code'];
}
if (is_string($language)) { $code = $language; }
?> ?>
<li> <li>
<strong><?php echo $this->all_languages[$code] ?></strong> <strong>
<?php echo $name ?>
<?php if ($
</strong>
| <a class="verify" href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'delete'), $nonce_url) ?>">Delete</a> | <a class="verify" href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'delete'), $nonce_url) ?>">Delete</a>
</li> </li>
<?php } ?> <?php } ?>

View File

@ -76,7 +76,30 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$this->assertTrue($options['only_allowed_users']); $this->assertTrue($options['only_allowed_users']);
}
function testBuildFullDefaultLanguageInfo() {
$admin = new WhatDidTheySayAdmin();
$admin->all_languages = array(
'en' => 'English',
'de' => 'German',
'fr' => 'French'
);
$admin->default_options = array(
'languages' => array(
'en',
array('code' => 'de', 'default' => true),
'it'
)
);
$this->assertEquals(
array(
'en' => array('name' => 'English'),
'de' => array('name' => 'German', 'default' => true),
), $admin->build_default_languages()
);
} }
} }