| 1 |
<?php |
| 2 |
// displays the Languages admin panel |
| 3 |
?> |
| 4 |
<div class="wrap"> |
| 5 |
<?php screen_icon('options-general'); ?> |
| 6 |
<h2 class="nav-tab-wrapper"><?php |
| 7 |
// display tabs |
| 8 |
foreach ($tabs as $key=>$name) |
| 9 |
printf('<a href="options-general.php?page=mlang&tab=%s" class="nav-tab %s">%s</a>', $key, $key == $active_tab ? 'nav-tab-active' : '', $name);?> |
| 10 |
</h2><?php |
| 11 |
|
| 12 |
switch($active_tab) { |
| 13 |
|
| 14 |
// Languages tab |
| 15 |
case 'lang': |
| 16 |
|
| 17 |
if (isset($_GET['error'])) {?> |
| 18 |
<div id="message" class="error fade"><p><?php echo $errors[$_GET['error']]; ?></p></div><?php |
| 19 |
}?> |
| 20 |
|
| 21 |
<div id="col-container"> |
| 22 |
<div id="col-right"> |
| 23 |
<div class="col-wrap"><?php |
| 24 |
// displays the language list in a table |
| 25 |
$list_table->display(); ?> |
| 26 |
</div><!-- col-wrap --> |
| 27 |
</div><!-- col-right --> |
| 28 |
|
| 29 |
<div id="col-left"> |
| 30 |
<div class="col-wrap"> |
| 31 |
|
| 32 |
<div class="form-wrap"> |
| 33 |
<h3><?php echo $action=='edit' ? _e('Edit language','polylang') : _e('Add new language','polylang'); ?></h3><?php |
| 34 |
|
| 35 |
// displays the add (or edit) language form |
| 36 |
// The term fields are used as follows : |
| 37 |
// name -> language name (used only for display) |
| 38 |
// slug -> language code (ideally 2-letters ISO 639-1 language code but I currently use it only as slug so it doesn't matter) |
| 39 |
// description -> WordPress Locale for the language. Here if something wrong is used, the .mo files will not be loaded... |
| 40 |
|
| 41 |
// adds noheader=true in the action url to allow using wp_redirect when processing the form ?> |
| 42 |
<form id="add-lang" method="post" action="admin.php?page=mlang&noheader=true" class="validate"> |
| 43 |
<?php wp_nonce_field('add-lang', '_wpnonce_add-lang'); |
| 44 |
|
| 45 |
if ($action=='edit') {?> |
| 46 |
<input type="hidden" name="action" value="update" /> |
| 47 |
<input type="hidden" name="lang_id" value="<?php echo esc_attr($edit_lang->term_id);?>" /><?php |
| 48 |
} |
| 49 |
else { ?> |
| 50 |
<input type="hidden" name="action" value="add" /><?php |
| 51 |
}?> |
| 52 |
|
| 53 |
<div class="form-field"> |
| 54 |
<label for="lang_list"><?php _e('Choose a language', 'polylang');?></label> |
| 55 |
<select name="lang_list" id="lang_list"> |
| 56 |
<option value=""></option>';<?php |
| 57 |
include(PLL_INC.'/languages.php'); |
| 58 |
foreach ($languages as $key=>$lang) { |
| 59 |
printf("<option value='%s-%s'>%s</option>\n", esc_attr($key), esc_attr($lang[0]), esc_html($lang[1])); |
| 60 |
} ?> |
| 61 |
</select> |
| 62 |
<p><?php _e('You can choose a language in the list or directly edit it below.', 'polylang');?></p> |
| 63 |
</div> |
| 64 |
|
| 65 |
<div class="form-field form-required"> |
| 66 |
<label for="name"><?php _e('Full name', 'polylang');?></label> |
| 67 |
<input name="name" id="name" type="text" value="<?php if ($action=='edit') echo esc_attr($edit_lang->name);?>" size="40" aria-required="true" /> |
| 68 |
<p><?php _e('The name is how it is displayed on your site (for example: English).', 'polylang');?></p> |
| 69 |
</div> |
| 70 |
|
| 71 |
<div class="form-field form-required"> |
| 72 |
<label for="description"><?php _e('Locale', 'polylang');?></label><?php |
| 73 |
printf('<input name="description" id="description" type="text" value="%s" size="5" maxlength="5" aria-required="true" />', |
| 74 |
$action=='edit' ? esc_attr($edit_lang->description) : '');?> |
| 75 |
<p><?php _e('Wordpress Locale for the language (for example: en_US). You will need to install the .mo file for this language.', 'polylang');?></p> |
| 76 |
</div> |
| 77 |
|
| 78 |
<div class="form-field"> |
| 79 |
<label for="slug"><?php _e('Language code', 'polylang');?></label> |
| 80 |
<input name="slug" id="slug" type="text" value="<?php if ($action=='edit') echo esc_attr($edit_lang->slug);?>" size="2" maxlength="2"/> |
| 81 |
<p><?php _e('2-letters ISO 639-1 language code (for example: en)', 'polylang');?></p> |
| 82 |
</div> |
| 83 |
|
| 84 |
<?php submit_button( $action == 'edit' ? __('Update') : __('Add new language', 'polylang'), 'button'); // since WP 3.1 ?> |
| 85 |
|
| 86 |
</form> |
| 87 |
</div><!-- form-wrap --> |
| 88 |
</div><!-- col-wrap --> |
| 89 |
</div><!-- col-left --> |
| 90 |
</div><!-- col-container --><?php |
| 91 |
break; |
| 92 |
|
| 93 |
// menu tab |
| 94 |
case 'menus': ?> |
| 95 |
|
| 96 |
<div class="form-wrap"> |
| 97 |
<form id="nav-menus-lang" method="post" action="admin.php?page=mlang&tab=menus" class="validate"> |
| 98 |
<?php wp_nonce_field('nav-menus-lang', '_wpnonce_nav-menus-lang');?> |
| 99 |
<input type="hidden" name="action" value="nav-menus" /><?php |
| 100 |
|
| 101 |
foreach ( $locations as $location => $description ) {?> |
| 102 |
<h3><?php echo esc_html($description); ?></h3> |
| 103 |
<table class="form-table"><?php |
| 104 |
foreach ($listlanguages as $language) {?> |
| 105 |
<tr><?php printf('<th><label for="menu-lang-%1$s-%2$s">%3$s</label></th>', esc_attr($location), esc_attr($language->slug), esc_html($language->name));?> |
| 106 |
<td><?php printf('<select name="menu-lang[%1$s][%2$s]" id="menu-lang-%1$s-%2$s">', esc_attr($location), esc_attr($language->slug));?> |
| 107 |
<option value="0"></option><?php |
| 108 |
foreach ($menus as $menu) { |
| 109 |
printf( |
| 110 |
"<option value='%d'%s>%s</option>\n", |
| 111 |
esc_attr($menu->term_id), |
| 112 |
isset($menu_lang[$location][$language->slug]) && $menu_lang[$location][$language->slug] == $menu->term_id ? ' selected="selected"' : '', |
| 113 |
esc_html($menu->name) |
| 114 |
); |
| 115 |
} ?> |
| 116 |
</select></td> |
| 117 |
</tr><?php |
| 118 |
}?> |
| 119 |
<tr> |
| 120 |
<th><?php _e('Language switcher', 'polylang') ?></th> |
| 121 |
<td><?php |
| 122 |
foreach ($menu_options as $key => $str) |
| 123 |
printf('<label><input name="menu-lang[%1$s][%2$s]" type="checkbox" value="1" %3$s /> %4$s</label>', |
| 124 |
esc_attr($location), esc_attr($key), $menu_lang[$location][$key] ? 'checked="checked"' :'', esc_html($str));?> |
| 125 |
</td> |
| 126 |
</tr> |
| 127 |
</table><?php |
| 128 |
} |
| 129 |
|
| 130 |
submit_button(); // since WP 3.1 ?> |
| 131 |
|
| 132 |
</form> |
| 133 |
</div><!-- form-wrap --><?php |
| 134 |
break; |
| 135 |
|
| 136 |
// settings tab |
| 137 |
case 'settings': ?> |
| 138 |
|
| 139 |
<div class="form-wrap"> |
| 140 |
<form id="options-lang" method="post" action="admin.php?page=mlang&tab=settings" class="validate"> |
| 141 |
<?php wp_nonce_field('options-lang', '_wpnonce_options-lang');?> |
| 142 |
<input type="hidden" name="action" value="options" /> |
| 143 |
|
| 144 |
<table class="form-table"> |
| 145 |
|
| 146 |
<tr> |
| 147 |
<th><label for='default_lang'><?php _e('Default language', 'polylang');?></label></th> |
| 148 |
<td> |
| 149 |
<select name="default_lang" id="default_lang"><?php |
| 150 |
foreach ($listlanguages as $language) { |
| 151 |
printf( |
| 152 |
"<option value='%s'%s>%s</option>\n", |
| 153 |
esc_attr($language->slug), |
| 154 |
$options['default_lang'] == $language->slug ? ' selected="selected"' : '', |
| 155 |
esc_html($language->name) |
| 156 |
); |
| 157 |
} ?> |
| 158 |
</select> |
| 159 |
</td> |
| 160 |
</tr><?php |
| 161 |
|
| 162 |
// posts or terms without language set |
| 163 |
if (!empty($posts) || !empty($terms) && $options['default_lang']) { |
| 164 |
|
| 165 |
if (!empty($posts)) |
| 166 |
echo '<input type="hidden" name="posts" value="'.esc_attr($posts).'" />'; |
| 167 |
if (!empty($terms)) |
| 168 |
echo '<input type="hidden" name="terms" value="'.esc_attr($terms).'" />';?> |
| 169 |
|
| 170 |
<tr> |
| 171 |
<th></th> |
| 172 |
<td> |
| 173 |
<label style="color: red"><?php |
| 174 |
printf( |
| 175 |
'<input name="fill_languages" type="checkbox" value="1" /> %s', |
| 176 |
__('There are posts, pages, categories or tags without language set. Do you want to set them all to default language ?', 'polylang') |
| 177 |
);?> |
| 178 |
</label> |
| 179 |
</td> |
| 180 |
</tr><?php |
| 181 |
}?> |
| 182 |
|
| 183 |
<tr> |
| 184 |
<th><?php _e('Detect browser language', 'polylang');?></th> |
| 185 |
<td> |
| 186 |
<label><?php |
| 187 |
printf( |
| 188 |
'<input name="browser" type="checkbox" value="1" %s /> %s', |
| 189 |
$options['browser'] ? 'checked="checked"' :'', |
| 190 |
__('When the front page is visited, set the language according to the browser preference', 'polylang') |
| 191 |
);?> |
| 192 |
</label> |
| 193 |
</td> |
| 194 |
</tr> |
| 195 |
|
| 196 |
<tr> |
| 197 |
<th><?php _e('URL modifications', 'polylang') ?></th> |
| 198 |
<td scope="row"> |
| 199 |
<label><?php |
| 200 |
printf( |
| 201 |
'<input name="rewrite" type="radio" value="0" %s /> %s %s', |
| 202 |
$options['rewrite'] ? '' : 'checked="checked"', |
| 203 |
__('Keep /language/ in pretty permalinks. Example:', 'polylang'), |
| 204 |
'<code>'.esc_html(home_url('language/en/')).'</code>' |
| 205 |
);?> |
| 206 |
</label> |
| 207 |
<label><?php |
| 208 |
printf( |
| 209 |
'<input name="rewrite" type="radio" value="1" %s /> %s %s', |
| 210 |
$options['rewrite'] ? 'checked="checked"' : '', |
| 211 |
__('Remove /language/ in pretty permalinks. Example:', 'polylang'), |
| 212 |
'<code>'.esc_html(home_url('en/')).'</code>' |
| 213 |
);?> |
| 214 |
</label> |
| 215 |
<label><?php |
| 216 |
printf( |
| 217 |
'<input name="hide_default" type="checkbox" value="1" %s /> %s', |
| 218 |
$options['hide_default'] ? 'checked="checked"' :'', |
| 219 |
__('Hide URL language information for default language', 'polylang') |
| 220 |
);?> |
| 221 |
</label> |
| 222 |
</td> |
| 223 |
</tr> |
| 224 |
|
| 225 |
</table> |
| 226 |
|
| 227 |
<?php submit_button(); // since WP 3.1 ?> |
| 228 |
|
| 229 |
</form> |
| 230 |
</div><!-- form-wrap --><?php |
| 231 |
break; |
| 232 |
|
| 233 |
default: |
| 234 |
break; |
| 235 |
}?> |
| 236 |
|
| 237 |
</div><!-- wrap --> |
| 238 |
|