Polylang - Version 0.4.3

Version Description

(2011-11-19) =

  • Add Russian translation contributed by yoyurec
  • Bug correction: Impossible to suppress the language name in the language switcher widget settings
  • Bug correction: Post's page does not work when using a static front page
  • Bug correction: Flags in local_flags directory are removed after an automatic upgrade (should now work for an upgrade from 0.4.3+ to a higher version)
  • Bug correction: Switching to default language displays a 404 Error when hiding the default language in url and displaying the language switcher as dropdown
  • Other minor bug corrections
  • Tests done with WordPress 3.3 beta 3
Download this release

Release Info

Developer Chouby
Plugin Icon 128x128 Polylang
Version 0.4.3
Comparing to
See all releases

Code changes from version 0.4.2 to 0.4.3

doc/documentation-en.odt CHANGED
Binary file
doc/documentation-en.pdf CHANGED
Binary file
flags/ru_RU.png ADDED
Binary file
include/admin.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php
2
 
3
- require_once( ABSPATH . WPINC . '/pluggable.php' ); // to ensure that 'get_current_user_id' is defined
4
-
5
  require_once(INC_DIR.'/list-table.php');
6
 
7
  class Polylang_Admin extends Polylang_Base {
@@ -57,7 +55,7 @@ class Polylang_Admin extends Polylang_Base {
57
  }
58
 
59
  function admin_init() {
60
- // add these actions and filters here and not in the constructor to be sure all taxonomies are registered
61
  foreach (get_taxonomies(array('show_ui'=>true)) as $tax) {
62
  // adds the language field in the 'Categories' and 'Post Tags' panels
63
  add_action($tax.'_add_form_fields', array(&$this, 'add_term_form'));
@@ -77,9 +75,9 @@ class Polylang_Admin extends Polylang_Base {
77
 
78
  // manage versions
79
  $options = get_option('polylang');
80
- if ($options['version'] < POLYLANG_VERSION) {
81
 
82
- if($options['version'] < '0.4')
83
  $options['hide_default'] = 0; // option introduced in 0.4
84
 
85
  $options['version'] = POLYLANG_VERSION;
@@ -144,7 +142,7 @@ class Polylang_Admin extends Polylang_Base {
144
  break;
145
 
146
  case 'delete':
147
- check_admin_referer( 'delete-lang');
148
 
149
  if (isset($_GET['lang']) && $_GET['lang']) {
150
  $lang_id = (int) $_GET['lang'];
@@ -598,13 +596,12 @@ class Polylang_Admin extends Polylang_Base {
598
  }
599
 
600
  // modifies the theme location nav menu metabox
 
601
  function nav_menu_theme_locations() {
602
  // only if the theme supports nav menus and a nav menu exists
603
- if ( ! current_theme_supports( 'menus' ) || !isset($_REQUEST['menu']) )
604
  return;
605
 
606
- // thanks to: http://wordpress.stackexchange.com/questions/2770/how-to-add-a-custom-metabox-to-the-menu-management-admin-screen
607
- $metabox = &$GLOBALS['wp_meta_boxes']['nav-menus']['side']['default']['nav-menu-theme-locations'];
608
  $metabox['callback'] = array(&$this,'nav_menu_language');
609
  $metabox['title'] = __('Theme locations and languages', 'polylang');
610
  }
@@ -649,8 +646,10 @@ class Polylang_Admin extends Polylang_Base {
649
 
650
  // returns the locale based on user preference
651
  function get_locale($locale) {
652
- $loc = get_user_meta(get_current_user_id(), 'user_lang', 'true');
653
- return $loc ? $loc : $locale;
 
 
654
  }
655
 
656
  // updates language user preference
1
  <?php
2
 
 
 
3
  require_once(INC_DIR.'/list-table.php');
4
 
5
  class Polylang_Admin extends Polylang_Base {
55
  }
56
 
57
  function admin_init() {
58
+ // add these actions and filters here and not in the constructor to be sure that all taxonomies are registered
59
  foreach (get_taxonomies(array('show_ui'=>true)) as $tax) {
60
  // adds the language field in the 'Categories' and 'Post Tags' panels
61
  add_action($tax.'_add_form_fields', array(&$this, 'add_term_form'));
75
 
76
  // manage versions
77
  $options = get_option('polylang');
78
+ if (version_compare($options['version'], POLYLANG_VERSION, '<')) {
79
 
80
+ if(version_compare($options['version'], '0.4', '<'))
81
  $options['hide_default'] = 0; // option introduced in 0.4
82
 
83
  $options['version'] = POLYLANG_VERSION;
142
  break;
143
 
144
  case 'delete':
145
+ check_admin_referer('delete-lang');
146
 
147
  if (isset($_GET['lang']) && $_GET['lang']) {
148
  $lang_id = (int) $_GET['lang'];
596
  }
597
 
598
  // modifies the theme location nav menu metabox
599
+ // thanks to: http://wordpress.stackexchange.com/questions/2770/how-to-add-a-custom-metabox-to-the-menu-management-admin-screen
600
  function nav_menu_theme_locations() {
601
  // only if the theme supports nav menus and a nav menu exists
602
+ if ( ! current_theme_supports( 'menus' ) || ! $metabox = &$GLOBALS['wp_meta_boxes']['nav-menus']['side']['default']['nav-menu-theme-locations'] )
603
  return;
604
 
 
 
605
  $metabox['callback'] = array(&$this,'nav_menu_language');
606
  $metabox['title'] = __('Theme locations and languages', 'polylang');
607
  }
646
 
647
  // returns the locale based on user preference
648
  function get_locale($locale) {
649
+ // get_current_user_id uses wp_get_current_user which may not be available the first time(s) get_locale is called
650
+ if (function_exists('wp_get_current_user'))
651
+ $loc = get_user_meta(get_current_user_id(), 'user_lang', 'true');
652
+ return isset($loc) && $loc ? $loc : $locale;
653
  }
654
 
655
  // updates language user preference
include/list-table.php CHANGED
@@ -3,7 +3,7 @@
3
  // Thanks to Matt Van Andel (http://www.mattvanandel.com) for most of this code !
4
 
5
  if(!class_exists('WP_List_Table')){
6
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
7
  }
8
 
9
  class Polylang_List_Table extends WP_List_Table {
3
  // Thanks to Matt Van Andel (http://www.mattvanandel.com) for most of this code !
4
 
5
  if(!class_exists('WP_List_Table')){
6
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); // since WP 3.1
7
  }
8
 
9
  class Polylang_List_Table extends WP_List_Table {
include/widget.php CHANGED
@@ -23,10 +23,19 @@ class Polylang_Widget extends WP_Widget {
23
  // keep the things simple for now as we switch to the posts page
24
  if ($dropdown) {
25
  $url = home_url('?lang=');
 
 
 
 
26
  $js = "
27
  <script type='text/javascript'>
28
  var d = document.getElementById('lang_choice');
29
- d.onchange = function() {location.href ='$url'+this.value;}
 
 
 
 
 
30
  </script>";
31
 
32
  echo $js;
@@ -36,7 +45,6 @@ class Polylang_Widget extends WP_Widget {
36
  // updates the widget options
37
  function update( $new_instance, $old_instance ) {
38
  $instance = $old_instance;
39
- $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'show_names' => 1, 'show_flags' => 0, 'dropdown' => 0) ); // default values
40
  $instance['title'] = strip_tags($new_instance['title']);
41
  $instance['show_names'] = !empty($new_instance['show_names']) ? 1 : 0;
42
  $instance['show_flags'] = !empty($new_instance['show_flags']) ? 1 : 0;
23
  // keep the things simple for now as we switch to the posts page
24
  if ($dropdown) {
25
  $url = home_url('?lang=');
26
+ $home_url = get_option('home');
27
+ $options = get_option('polylang');
28
+ $default = $options['hide_default'] ? $options['default_lang'] : '';
29
+
30
  $js = "
31
  <script type='text/javascript'>
32
  var d = document.getElementById('lang_choice');
33
+ d.onchange = function() {
34
+ if (this.value == '$default')
35
+ location.href = '$home_url';
36
+ else
37
+ location.href ='$url'+this.value;
38
+ }
39
  </script>";
40
 
41
  echo $js;
45
  // updates the widget options
46
  function update( $new_instance, $old_instance ) {
47
  $instance = $old_instance;
 
48
  $instance['title'] = strip_tags($new_instance['title']);
49
  $instance['show_names'] = !empty($new_instance['show_names']) ? 1 : 0;
50
  $instance['show_flags'] = !empty($new_instance['show_flags']) ? 1 : 0;
languages/polylang-de_DE.mo CHANGED
Binary file
languages/polylang-de_DE.po CHANGED
@@ -10,7 +10,7 @@ msgstr ""
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
- "Plural-Forms: nplurals=2: nplural=n>1\n"
14
  "X-Poedit-SourceCharset: utf-8\n"
15
  "X-Poedit-KeywordsList: _e;__;_c\n"
16
  "X-Poedit-Basepath: .\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
14
  "X-Poedit-SourceCharset: utf-8\n"
15
  "X-Poedit-KeywordsList: _e;__;_c\n"
16
  "X-Poedit-Basepath: .\n"
languages/polylang-ru_RU.mo ADDED
Binary file
languages/polylang-ru_RU.po ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: polylang\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2011-11-14 21:57+0100\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: YoYurec <yoyurec@gmail.com>\n"
8
+ "Language-Team: \n"
9
+ "Language: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
14
+ "X-Poedit-SourceCharset: utf-8\n"
15
+ "X-Poedit-KeywordsList: _e;__;_c\n"
16
+ "X-Poedit-Basepath: .\n"
17
+ "X-Poedit-Language: Russian\n"
18
+ "X-Poedit-Country: RUSSIAN FEDERATION\n"
19
+ "X-Poedit-SearchPath-0: ..\n"
20
+ "X-Poedit-SearchPath-1: ../include\n"
21
+
22
+ #: ../include/edit-term-form.php:6
23
+ #: ../include/admin.php:348
24
+ #: ../include/admin.php:502
25
+ #: ../include/term-translations.php:14
26
+ #: ../include/add-term-form.php:3
27
+ #: ../include/list-table.php:12
28
+ #: ../include/post-translations.php:4
29
+ msgid "Language"
30
+ msgstr "Язык"
31
+
32
+ #: ../include/edit-term-form.php:18
33
+ #: ../include/add-term-form.php:10
34
+ msgid "Sets the language"
35
+ msgstr "Устанавливает язык"
36
+
37
+ #: ../include/widget.php:5
38
+ msgid "Displays a language switcher"
39
+ msgstr "Показывает переключатель языков"
40
+
41
+ #: ../include/widget.php:6
42
+ msgid "Language Switcher"
43
+ msgstr "Переключатель языков"
44
+
45
+ #: ../include/widget.php:50
46
+ msgid "Display language names"
47
+ msgstr "Показывать названия языков"
48
+
49
+ #: ../include/widget.php:56
50
+ msgid "Display flags"
51
+ msgstr "Показывать флаги"
52
+
53
+ #: ../include/widget.php:62
54
+ msgid "Display as dropdown"
55
+ msgstr "Показывать как выпадающий список"
56
+
57
+ #: ../include/admin.php:90
58
+ msgid "Settings"
59
+ msgstr "Настройки"
60
+
61
+ #: ../include/admin.php:97
62
+ #: ../include/admin.php:392
63
+ #: ../include/list-table.php:13
64
+ #: ../include/languages-form.php:14
65
+ msgid "Languages"
66
+ msgstr "Языки"
67
+
68
+ #: ../include/admin.php:309
69
+ msgid "Enter a valid WorPress locale"
70
+ msgstr "Введите корректную WordPress локаль"
71
+
72
+ #: ../include/admin.php:310
73
+ msgid "The language code must be 2 characters long"
74
+ msgstr "Код языка должен состоять из 2-х символов"
75
+
76
+ #: ../include/admin.php:311
77
+ msgid "The language code must be unique"
78
+ msgstr "Код языка должен быть уникальным"
79
+
80
+ #: ../include/admin.php:312
81
+ msgid "The language must have a name"
82
+ msgstr "У языка должно быть название"
83
+
84
+ #: ../include/admin.php:380
85
+ msgid "Show all languages"
86
+ msgstr "Показать все языки"
87
+
88
+ #: ../include/admin.php:607
89
+ msgid "Theme locations and languages"
90
+ msgstr "Расположение темы и языков"
91
+
92
+ #: ../include/admin.php:612
93
+ #, php-format
94
+ msgid "Please go to the %slanguages page%s to set theme locations and languages"
95
+ msgstr "Перейдите на %slanguages page% для указания расположения темы и языков"
96
+
97
+ #: ../include/admin.php:624
98
+ msgid "The widget is displayed for:"
99
+ msgstr "Показывать виджет для"
100
+
101
+ #: ../include/admin.php:627
102
+ msgid "All languages"
103
+ msgstr "Все языки"
104
+
105
+ #: ../include/post-metabox.php:3
106
+ msgid "Page's language:"
107
+ msgstr "Язык страницы"
108
+
109
+ #: ../include/post-metabox.php:3
110
+ msgid "Post's language:"
111
+ msgstr "Язык записи"
112
+
113
+ #: ../include/term-translations.php:5
114
+ #: ../include/term-translations.php:9
115
+ msgid "Translations"
116
+ msgstr "Переводы"
117
+
118
+ #: ../include/term-translations.php:14
119
+ msgid "Translation"
120
+ msgstr "Перевод"
121
+
122
+ #: ../include/term-translations.php:14
123
+ #: ../include/term-translations.php:75
124
+ #: ../include/list-table.php:32
125
+ #: ../include/post-translations.php:6
126
+ #: ../include/post-translations.php:28
127
+ msgid "Edit"
128
+ msgstr "Редактировать"
129
+
130
+ #: ../include/term-translations.php:61
131
+ #: ../include/post-translations.php:33
132
+ msgid "Add new"
133
+ msgstr "Добавить новый"
134
+
135
+ #: ../include/list-table.php:33
136
+ msgid "Delete"
137
+ msgstr "Удалить"
138
+
139
+ #: ../include/list-table.php:50
140
+ #: ../include/languages-form.php:50
141
+ msgid "Full name"
142
+ msgstr "Полное название"
143
+
144
+ #: ../include/list-table.php:51
145
+ #: ../include/languages-form.php:56
146
+ msgid "Locale"
147
+ msgstr "Локаль"
148
+
149
+ #: ../include/list-table.php:52
150
+ msgid "Code"
151
+ msgstr "Код"
152
+
153
+ #: ../include/list-table.php:53
154
+ msgid "Posts"
155
+ msgstr "Записи"
156
+
157
+ #: ../include/languages-form.php:33
158
+ msgid "Edit language"
159
+ msgstr "Редактировать язык"
160
+
161
+ #: ../include/languages-form.php:33
162
+ #: ../include/languages-form.php:70
163
+ msgid "Add new language"
164
+ msgstr "Добавить новый язык"
165
+
166
+ #: ../include/languages-form.php:52
167
+ msgid "The name is how it is displayed on your site (for example: English)."
168
+ msgstr "Название для отображения на сайте (например: Русский)."
169
+
170
+ #: ../include/languages-form.php:58
171
+ msgid "Wordpress Locale for the language (for example: en_US). You will need to install the .mo file for this language."
172
+ msgstr "Локаль Wordpress'a для языка (например: ru_RU). Вы должны установить файлы .mo для админ.панели и используемой темы."
173
+
174
+ #: ../include/languages-form.php:62
175
+ msgid "Language code"
176
+ msgstr "Код языка"
177
+
178
+ #: ../include/languages-form.php:64
179
+ msgid "2-letters ISO 639-1 language code (for example: en)"
180
+ msgstr "2х-буквенный ISO 639-1 код языка (например: ru)"
181
+
182
+ #: ../include/languages-form.php:68
183
+ msgid "Update"
184
+ msgstr "Обновить"
185
+
186
+ #: ../include/languages-form.php:82
187
+ msgid "Menus"
188
+ msgstr "Меню"
189
+
190
+ #: ../include/languages-form.php:90
191
+ msgid "Theme location"
192
+ msgstr "Расположение темы"
193
+
194
+ #: ../include/languages-form.php:134
195
+ msgid "Options"
196
+ msgstr "Настройки"
197
+
198
+ #: ../include/languages-form.php:143
199
+ msgid "Default language"
200
+ msgstr "Язык по-умолчанию"
201
+
202
+ #: ../include/languages-form.php:172
203
+ msgid "There are posts, pages, categories or tags without language set. Do you want to set them all to default language ?"
204
+ msgstr "Найдены записи, страницы, категории или метки без указанния какого-либо языка. Установить им язык по-умолчанию?"
205
+
206
+ #: ../include/languages-form.php:180
207
+ msgid "Detect browser language"
208
+ msgstr "Определять язык в браузере"
209
+
210
+ #: ../include/languages-form.php:186
211
+ msgid "When the front page is visited, set the language according to the browser preference"
212
+ msgstr "Установить язык сайта согласно настройкам браузера"
213
+
214
+ #: ../include/languages-form.php:193
215
+ msgid "URL modifications"
216
+ msgstr "Модификации URL"
217
+
218
+ #: ../include/languages-form.php:199
219
+ msgid "Keep /language/ in pretty permalinks. Example: "
220
+ msgstr "Оставить /language/ в ЧПУ. Пример: "
221
+
222
+ #: ../include/languages-form.php:207
223
+ msgid "Remove /language/ in pretty permalinks. Example: "
224
+ msgstr "Удалить /language/ в ЧПУ. Пример: "
225
+
226
+ #: ../include/languages-form.php:215
227
+ msgid "Hide URL language information for default language"
228
+ msgstr "Спрятать название языка по-умолчанию из URL"
229
+
230
+ #: ../include/post-translations.php:1
231
+ msgid "ID of pages in other languages:"
232
+ msgstr "ID страницы на других языках:"
233
+
234
+ #: ../include/post-translations.php:1
235
+ msgid "ID of posts in other languages:"
236
+ msgstr "ID записи на других языках:"
237
+
238
+ #: ../include/post-translations.php:5
239
+ msgid "Page ID"
240
+ msgstr "ID страницы"
241
+
242
+ #: ../include/post-translations.php:5
243
+ msgid "Post ID"
244
+ msgstr "ID записи"
245
+
246
+ #: ../include/personal-options.php:3
247
+ msgid "Admin language"
248
+ msgstr "Язык админ.панели"
249
+
250
+ msgid "Title:"
251
+ msgstr "Titre :"
252
+
polylang.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://wordpress.org/extend/plugins/polylang/
5
- Version: 0.4.2
6
  Author: F. Demarle
7
  Description: Adds multilingual capability to Wordpress
8
  */
@@ -23,13 +23,11 @@ Description: Adds multilingual capability to Wordpress
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
 
26
- define('POLYLANG_VERSION', '0.4.1');
27
 
28
  define('POLYLANG_DIR', dirname(__FILE__));
29
  define('INC_DIR', POLYLANG_DIR.'/include');
30
 
31
- require_once(ABSPATH . 'wp-admin/includes/template.php'); // to ensure that 'get_current_screen' is defined
32
-
33
  require_once(INC_DIR.'/base.php');
34
  require_once(INC_DIR.'/admin.php');
35
  require_once(INC_DIR.'/widget.php');
@@ -45,6 +43,10 @@ class Polylang extends Polylang_Base {
45
  register_activation_hook( __FILE__, array(&$this, 'activate') );
46
  register_deactivation_hook( __FILE__, array(&$this, 'deactivate') );
47
 
 
 
 
 
48
  // plugin and widget initialization
49
  add_action('init', array(&$this, 'init'));
50
  add_action('widgets_init', array(&$this, 'widgets_init'));
@@ -175,6 +177,55 @@ class Polylang extends Polylang_Base {
175
  $wp_rewrite->flush_rules();
176
  }
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  // some initialization
179
  function init() {
180
  global $wpdb;
@@ -265,16 +316,16 @@ class Polylang extends Polylang_Base {
265
  }
266
 
267
  if (is_admin()) {
268
- $screen = get_current_screen(); // since WP 3.1
269
 
270
- // NOTE: $screen is not defined in the tag cloud of the Edit Post panel ($pagenow set to admin-ajax.php)
271
- if (isset($screen))
272
- // does nothing in the Categories, Post tags, Languages and Posts* admin panels
273
- if ($screen->base == 'edit-tags' || $screen->base == 'toplevel_page_mlang' || $screen->base == 'edit')
274
- return $clauses;
 
275
 
276
- // *FIXME I want all categories in the dropdown list and only the ones in the right language in the inline edit
277
- // It seems that I need javascript to get the post_id as inline edit data are manipulated in inline-edit-post.js
278
 
279
  $this->curlang = $this->get_current_language();
280
  }
@@ -443,6 +494,19 @@ class Polylang extends Polylang_Base {
443
  }
444
  }
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  // FIXME to generalize as I probably forget things
447
  // sets the language in case we hide the default language
448
  if ( $options['hide_default'] && !isset($qvars['lang']) && (
@@ -642,6 +706,10 @@ class Polylang extends Polylang_Base {
642
  if (is_single() && !is_attachment() && $id = $this->get_post(get_the_ID(), $language))
643
  $url = get_permalink($id);
644
 
 
 
 
 
645
  elseif (is_page() && $id = $this->get_post(get_the_ID(), $language))
646
  $url = $hide && $id == $this->get_post(get_option('page_on_front'), $language) ?
647
  get_option('home') :
@@ -779,6 +847,7 @@ class Polylang extends Polylang_Base {
779
 
780
  $flag = $show_flags && (
781
  file_exists(POLYLANG_DIR.($file = '/local_flags/'.$language->description.'.png')) ||
 
782
  file_exists(POLYLANG_DIR.($file = '/flags/'.$language->description.'.png')) ) ?
783
  '<img src="'.esc_url(WP_PLUGIN_URL.'/polylang'.$file).'" alt="'.esc_attr($language->name).'" />' : '';
784
 
2
  /*
3
  Plugin Name: Polylang
4
  Plugin URI: http://wordpress.org/extend/plugins/polylang/
5
+ Version: 0.4.3
6
  Author: F. Demarle
7
  Description: Adds multilingual capability to Wordpress
8
  */
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
 
26
+ define('POLYLANG_VERSION', '0.4.3');
27
 
28
  define('POLYLANG_DIR', dirname(__FILE__));
29
  define('INC_DIR', POLYLANG_DIR.'/include');
30
 
 
 
31
  require_once(INC_DIR.'/base.php');
32
  require_once(INC_DIR.'/admin.php');
33
  require_once(INC_DIR.'/widget.php');
43
  register_activation_hook( __FILE__, array(&$this, 'activate') );
44
  register_deactivation_hook( __FILE__, array(&$this, 'deactivate') );
45
 
46
+ // manages plugin upgrade
47
+ add_filter('upgrader_pre_install', array(&$this, 'pre_upgrade'));
48
+ add_filter('upgrader_post_install', array(&$this, 'post_upgrade'));
49
+
50
  // plugin and widget initialization
51
  add_action('init', array(&$this, 'init'));
52
  add_action('widgets_init', array(&$this, 'widgets_init'));
177
  $wp_rewrite->flush_rules();
178
  }
179
 
180
+ // saves the local_flags directory before upgrade
181
+ // FIXME cannot test before release of v0.4.3
182
+ function pre_upgrade() {
183
+ // nothing to backup
184
+ if (!@is_dir($flags_dir = POLYLANG_DIR . '/local_flags'))
185
+ return true;
186
+
187
+ $upgrade_dirs = array(
188
+ WP_CONTENT_DIR . '/upgrade',
189
+ WP_CONTENT_DIR . '/upgrade/polylang'
190
+ );
191
+
192
+ foreach ($upgrade_dirs as $dir) {
193
+ if (!@is_dir($dir) && !@mkdir($dir, 0755))
194
+ return new WP_Error('polylang_upgrade_error', sprintf('%s<br />%s <strong>%s</strong>',
195
+ __("Error: Upgrade directory doesn't exist!", 'polylang'),
196
+ __('Please create', 'polylang'),
197
+ $dir
198
+ ));
199
+ }
200
+
201
+ if (!@rename($flags_dir, WP_CONTENT_DIR . '/upgrade/polylang/local_flags'))
202
+ return new WP_Error('polylang_backup_error', sprintf('%s<br />%s <strong>%s</strong>',
203
+ __('Error: Backup of local flags failed!', 'polylang'),
204
+ __('Please backup', 'polylang'),
205
+ $flags_dir
206
+ ));
207
+
208
+ return true;
209
+ }
210
+
211
+ // restores the local_flags directory after upgrade
212
+ // FIXME cannot test before release of v0.4.3
213
+ function post_upgrade() {
214
+ // nothing to restore
215
+ if (!@is_dir($upgrade_dir = WP_CONTENT_DIR . '/upgrade/polylang/local_flags'))
216
+ return true;
217
+
218
+ if (!@rename($upgrade_dir, POLYLANG_DIR . '/local_flags'))
219
+ return new WP_Error('polylang_restore_error', sprintf('%s<br />%s (<strong>%s</strong>)',
220
+ __('Error: Restore of local flags failed!', 'polylang'),
221
+ __('Please restore your local flags', 'polylang'),
222
+ $upgrade_dir
223
+ ));
224
+
225
+ @rmdir(WP_CONTENT_DIR . '/upgrade/polylang');
226
+ return true;
227
+ }
228
+
229
  // some initialization
230
  function init() {
231
  global $wpdb;
316
  }
317
 
318
  if (is_admin()) {
 
319
 
320
+ if (function_exists('get_current_screen'))
321
+ $screen = get_current_screen(); // since WP 3.1, may not be available the first time(s) get_terms is called
322
+
323
+ // does nothing in the Categories, Post tags, Languages and Posts* admin panels
324
+ if (!isset($screen) || $screen->base == 'edit-tags' || $screen->base == 'toplevel_page_mlang' || $screen->base == 'edit')
325
+ return $clauses;
326
 
327
+ // *FIXME I want all categories in the dropdown list and only the ones in the right language in the inline edit
328
+ // It seems that I need javascript to get the post_id as inline edit data are manipulated in inline-edit-post.js
329
 
330
  $this->curlang = $this->get_current_language();
331
  }
494
  }
495
  }
496
 
497
+ // sets the language for posts page in case the front page displays a static page
498
+ if ($page_for_posts = get_option('page_for_posts') &&
499
+ isset($query->queried_object_id) &&
500
+ $this->get_post($query->queried_object_id, $this->get_post_language($page_for_posts)) == $page_for_posts
501
+ ) {
502
+ $query->set('lang',$this->get_post_language($query->queried_object_id)->slug);
503
+ $query->queried_object_id = get_option('page_for_posts');
504
+ $query->is_page = false;
505
+ $query->is_home = true;
506
+ $query->is_posts_page = true;
507
+ $query->is_singular = false;
508
+ }
509
+
510
  // FIXME to generalize as I probably forget things
511
  // sets the language in case we hide the default language
512
  if ( $options['hide_default'] && !isset($qvars['lang']) && (
706
  if (is_single() && !is_attachment() && $id = $this->get_post(get_the_ID(), $language))
707
  $url = get_permalink($id);
708
 
709
+ // page for posts
710
+ elseif (isset($wp_query->queried_object_id) && $wp_query->queried_object_id == ($page_for_posts = get_option('page_for_posts')))
711
+ $url = get_permalink($this->get_post($page_for_posts, $language));
712
+
713
  elseif (is_page() && $id = $this->get_post(get_the_ID(), $language))
714
  $url = $hide && $id == $this->get_post(get_option('page_on_front'), $language) ?
715
  get_option('home') :
847
 
848
  $flag = $show_flags && (
849
  file_exists(POLYLANG_DIR.($file = '/local_flags/'.$language->description.'.png')) ||
850
+ file_exists(POLYLANG_DIR.($file = '/local_flags/'.$language->description.'.jpg')) ||
851
  file_exists(POLYLANG_DIR.($file = '/flags/'.$language->description.'.png')) ) ?
852
  '<img src="'.esc_url(WP_PLUGIN_URL.'/polylang'.$file).'" alt="'.esc_attr($language->name).'" />' : '';
853
 
readme.txt CHANGED
@@ -1,17 +1,15 @@
1
  === Polylang ===
2
  Contributors: Chouby
3
- Tags: bilingual, multilingual, language, i18n, l10n, international, translate, translation, widget
4
  Requires at least: 3.1
5
- Tested up to: 3.2.1
6
- Stable tag: 0.4.2
7
 
8
- Adds multilingual support to WordPress.
9
 
10
  == Description ==
11
 
12
- Polylang adds multilingual support to WordPress. It acts as a language filter for posts you have written in several languages. It will however not make the translation for you ! If you are looking for automatic translation, look for another plugin. Unlike some other plugins, it does not integrate professionnal translation.
13
-
14
- You write posts, pages and create categories and post tags as usual. You just have to define the language and it will be displayed only if the visitor is browsing this language. Optionaly, you can mark each post, page, category and post tag to be the translation of another one. Thus if, for example, your visitor is reading a post, he can switch (using the language switcher widget provided with the plugin) to the same post translated in another language (provided that you translated it !).
15
 
16
  = Features =
17
 
@@ -21,16 +19,24 @@ You write posts, pages and create categories and post tags as usual. You just ha
21
  * Support for Search form (see FAQ)
22
  * Support for pretty permalinks
23
  * Support for static page (in the right language) used as front page
24
- * All WordPress default widgets are automatically in the right language : archives, categories, pages, recent comments, recent posts, tag cloud and calendar
25
- * All widgets can be displayed or not, depending on the language (new in 0.3)
26
  * Language switcher provided as a widget
27
- * The plugin admin is currently available in English, French and German
28
  * Each user can set the WordPress admin language in its profile (new in 0.4)
29
  * Support for custom post types and custom taxonomies (new in 0.4)
30
 
 
 
 
 
 
 
 
 
 
31
  = Notes =
32
 
33
- * The tests have been made with WordPress 3.2.1 and with the Twenty Eleven theme (see FAQ). Although I did not test previous versions, I see no reason why it should not work with WordPress 3.1. However the plugin should not work with WordPress 3.0.5 and lower.
34
  * Your server must run PHP5
35
  * Multisite is not supported yet.
36
  * You must deactivate other multilingual plugins before activating Polylang, otherwise, you may get unexpected results !
@@ -38,7 +44,11 @@ You write posts, pages and create categories and post tags as usual. You just ha
38
 
39
  = Feedback or ideas =
40
 
41
- You use the plugin or just tested it ? Don't hesitate to [give your feedback](http://wordpress.org/tags/polylang?forum_id=10). It will help making the plugin better. Don't hesitate to rate the plugin too.
 
 
 
 
42
 
43
  == Installation ==
44
 
@@ -63,52 +73,39 @@ qtranslate: I tested the version 2.5.23. As claimed by its author, it's probably
63
 
64
  In comparison to these plugins, Polylang tries to keep things simple and light, and does not mess your blog if you deactivate it. But it is still very young so be indulgent ;-)
65
 
66
- = The language filter is lost when using the search form =
67
-
68
- Your theme uses the template searchform.php (as Twenty Eleven does) or hardcoded the search form and javascript is disabled. Unfortunately Polylang currently does not support this. So you have the following alternatives to get the things work well:
69
 
70
- * Use the 'get_search_form' function and place your custom search form in functions.php as described in the [codex](http://codex.wordpress.org/Function_Reference/get_search_form). The plugin also works well if you use the default search form provided by WordPress.
71
- * Enable javascript (unfortunately you can't control this for your visitors so the first solution is better)
72
-
73
- = I activated the plugin and my posts are not displayed any more =
74
-
75
- You MUST define a language for all your posts and pages otherwise they will not pass the language filter...
76
-
77
- = I activated the plugin and my categories and post tags are not displayed any more =
78
-
79
- You MUST define a language for all your categories and post tags otherwise they will not pass the language filter...
80
 
81
  = Is Polylang compatible with multisite ? =
82
 
83
- Not yet.
84
-
85
- = Is it possible to display a language switcher without using the widget =
86
-
87
- It is possible to get a language switcher where you want in your theme without using the widget. For this, you can simply use in your theme the following instruction: `do_action('the_languages');`
88
 
89
  = Can I use my own flags for the language switcher ? =
90
 
91
- Yes. You have to use PNG files and name them with the WordPress locale. For example, en_US.png. Then upload these files in the `/polylang/local_flags` directory. Don't use the `/polylang/flags` directory as your files may be overwritten when updating the plugin.
92
 
93
  = Polylang does not come with a lot flags. Where can I find other flags ? =
94
 
95
  There are many sources. I included some of the [famfamfam](http://www.famfamfam.com) flags which I renamed.
96
 
97
- = How to know the current language in the theme ? =
98
 
99
- WordPress provides at least two functions for the theme or plugin author to know the current language:
100
- * `get_locale()` returns the WordPress locale in the format `en_US`
101
- * `get_bloginfo('language')` returns the locale in the format `en-US`
102
- Note the difference between '_' and '-' in the two functions.
103
- You can look at the following forum topics:
104
- [Return the current language as variable for your template](http://wordpress.org/support/topic/plugin-polylang-return-the-current-language-as-variable-for-your-template)
105
- [How to translate/switch specific contents on templates](http://wordpress.org/support/topic/plugin-polylang-how-to-translateswitch-specific-contents-on-templates.html)
106
 
107
- == Changelog ==
 
 
 
 
 
 
108
 
109
  = 0.4.2 (2011-11-16) =
110
 
111
- * Bug correction: language settings page is broken
112
 
113
  = 0.4.1 (2011-11-16) =
114
 
1
  === Polylang ===
2
  Contributors: Chouby
3
+ Tags: bilingual, language, i18n, international, l10n, localization, multilingual, translate, translation, widget
4
  Requires at least: 3.1
5
+ Tested up to: 3.3
6
+ Stable tag: 0.4.3
7
 
8
+ Polylang adds multilingual support to WordPress. You set a language for each post and it will be displayed only when browsing this language.
9
 
10
  == Description ==
11
 
12
+ You write posts, pages and create categories and post tags as usual, and then define the language for each of them. The translation is optional. A language switcher widget is provided with the plugin. The plugin does not integrate automatic or professional translation. You have to do the work yourself.
 
 
13
 
14
  = Features =
15
 
19
  * Support for Search form (see FAQ)
20
  * Support for pretty permalinks
21
  * Support for static page (in the right language) used as front page
22
+ * All WordPress default widgets (archives, categories, pages, recent comments, recent posts, tag cloud and calendar) are automatically in the right language
 
23
  * Language switcher provided as a widget
24
+ * All widgets can be displayed or not, depending on the language (new in 0.3)
25
  * Each user can set the WordPress admin language in its profile (new in 0.4)
26
  * Support for custom post types and custom taxonomies (new in 0.4)
27
 
28
+ The plugin admin interface is currently available in:
29
+
30
+ * English
31
+ * French
32
+ * German
33
+ * Russian contributed by [yoyurec](http://wordpress.org/support/profile/yoyurec)
34
+
35
+ Other translators are welcome ! [Contact me](http://www.flabellina.com/polylang-contact/). I am especially looking for someone who could replace me for the German translation which I did probably very bad...
36
+
37
  = Notes =
38
 
39
+ * The tests have been made with WordPress from version 3.1 up to 3.3 beta 3. The plugin does not work with WordPress 3.0.5 and lower.
40
  * Your server must run PHP5
41
  * Multisite is not supported yet.
42
  * You must deactivate other multilingual plugins before activating Polylang, otherwise, you may get unexpected results !
44
 
45
  = Feedback or ideas =
46
 
47
+ Don't hesitate to [give your feedback](http://wordpress.org/tags/polylang?forum_id=10). It will help making the plugin better. Don't hesitate to rate the plugin too.
48
+
49
+ == Upgrade Notice ==
50
+
51
+ Your custom flags in 'polylang/local_flags' directory will be removed when automatically upgrading from v0.4, v0.4.1, v0.4.2. So either do a manual upgrade or backup your custom flags. This problem should be solved when upgrading from v0.4.3 to a higher version.
52
 
53
  == Installation ==
54
 
73
 
74
  In comparison to these plugins, Polylang tries to keep things simple and light, and does not mess your blog if you deactivate it. But it is still very young so be indulgent ;-)
75
 
76
+ = Where to find help ? =
 
 
77
 
78
+ * A [documentation](http://plugins.svn.wordpress.org/polylang/trunk/doc/documentation-en.pdf) is supplied whith the plugin (look in the doc directory). I spent time to write it so please read it ! A FAQ is available at the end of the document.
79
+ * Search the [support forum](http://wordpress.org/tags/polylang?forum_id=10). Other people may had the same issue.
80
+ * If you still have a problem, open a new thread in the [support forum](http://wordpress.org/tags/polylang?forum_id=10)
 
 
 
 
 
 
 
81
 
82
  = Is Polylang compatible with multisite ? =
83
 
84
+ Not yet. It is planned for v0.5 (to be released before the end of the year)
 
 
 
 
85
 
86
  = Can I use my own flags for the language switcher ? =
87
 
88
+ Yes. You have to use PNG or JPG files and name them with the WordPress locale. For example, en_US.png. Then upload these files in the `/polylang/local_flags` directory. Don't use the `/polylang/flags` directory as your files may be overwritten when updating the plugin.
89
 
90
  = Polylang does not come with a lot flags. Where can I find other flags ? =
91
 
92
  There are many sources. I included some of the [famfamfam](http://www.famfamfam.com) flags which I renamed.
93
 
94
+ == Changelog ==
95
 
96
+ = 0.4.3 (2011-11-19) =
 
 
 
 
 
 
97
 
98
+ * Add Russian translation contributed by [yoyurec](http://wordpress.org/support/profile/yoyurec)
99
+ * Bug correction: Impossible to suppress the language name in the language switcher widget settings
100
+ * Bug correction: Post's page does not work when using a static front page
101
+ * Bug correction: Flags in local_flags directory are removed after an automatic upgrade (should now work for an upgrade from 0.4.3+ to a higher version)
102
+ * Bug correction: Switching to default language displays a 404 Error when hiding the default language in url and displaying the language switcher as dropdown
103
+ * Other minor bug corrections
104
+ * Tests done with WordPress 3.3 beta 3
105
 
106
  = 0.4.2 (2011-11-16) =
107
 
108
+ * Bug correction: language settings page is broken in v0.4.1
109
 
110
  = 0.4.1 (2011-11-16) =
111