Weglot Translate – Translate your WP website - Version 3.5

Version Description

(07/12/2021) =

  • Add: Autoswitch work on all page not only on homepage
  • Add: Exclude url doesn't generate redirection
  • Add: Add switcher from switcher editor
  • Add: Call API from cdn to translate
  • Add: Limited call API for deactivate account
  • Bugfix: Problem with gform and multisite
  • Bugfix: Fix hreflang generation with Cyrillic url
  • Bugfix: Weglot search option now works even if we're not on a main_query
Download this release

Release Info

Developer remyb92
Plugin Icon 128x128 Weglot Translate – Translate your WP website
Version 3.5
Comparing to
See all releases

Code changes from version 3.4 to 3.5

Files changed (83) hide show
  1. composer.json +3 -2
  2. languages/weglot-fr_FR.po +1 -1
  3. readme.txt +11 -9
  4. src/actions/admin/class-options-weglot.php +16 -12
  5. src/actions/front/class-front-enqueue-weglot.php +1 -0
  6. src/actions/front/class-front-menu-weglot.php +13 -28
  7. src/actions/front/class-search-weglot.php +1 -1
  8. src/actions/front/class-shortcode-weglot.php +0 -4
  9. src/actions/front/class-translate-page-weglot.php +12 -17
  10. src/helpers/class-helper-api.php +2 -0
  11. src/helpers/class-helper-filter-url-weglot.php +3 -2
  12. src/models/class-schema-option-v3.php +3 -0
  13. src/services/class-button-service-weglot.php +63 -43
  14. src/services/class-generate-switcher-service-weglot.php +69 -9
  15. src/services/class-href-lang-service-weglot.php +3 -1
  16. src/services/class-option-service-weglot.php +97 -3
  17. src/services/class-parser-service-weglot.php +7 -3
  18. src/services/class-redirect-service-weglot.php +29 -25
  19. src/services/class-replace-link-service-weglot.php +1 -1
  20. src/services/class-replace-url-service-weglot.php +27 -7
  21. src/services/class-request-url-service-weglot.php +9 -4
  22. src/services/class-translate-service-weglot.php +67 -20
  23. src/third/gravityforms/class-gf-filter-urls.php +5 -1
  24. src/third/woocommerce/class-wc-filter-urls-weglot.php +0 -1
  25. src/widgets/class-widget-selector-weglot.php +1 -3
  26. templates/admin/pages/tabs/advanced.php +81 -76
  27. templates/admin/pages/tabs/appearance.php +24 -3
  28. vendor/autoload.php +1 -1
  29. vendor/composer/InstalledVersions.php +5 -5
  30. vendor/composer/autoload_real.php +7 -7
  31. vendor/composer/autoload_static.php +5 -5
  32. vendor/composer/installed.json +6 -6
  33. vendor/composer/installed.php +5 -5
  34. vendor/weglot/weglot-php/.codeclimate.yml +0 -5
  35. vendor/weglot/weglot-php/.editorconfig +0 -8
  36. vendor/weglot/weglot-php/.env.dist +0 -9
  37. vendor/weglot/weglot-php/.github/ISSUE_TEMPLATE.md +0 -15
  38. vendor/weglot/weglot-php/.github/PULL_REQUEST_TEMPLATE.md +0 -11
  39. vendor/weglot/weglot-php/.github/workflows/php.yml +0 -72
  40. vendor/weglot/weglot-php/.travis.yml +0 -62
  41. vendor/weglot/weglot-php/examples/README.md +0 -15
  42. vendor/weglot/weglot-php/examples/cached-client-translate/.env.dist +0 -9
  43. vendor/weglot/weglot-php/examples/cached-client-translate/composer.json +0 -7
  44. vendor/weglot/weglot-php/examples/cached-client-translate/run.php +0 -78
  45. vendor/weglot/weglot-php/examples/parsing-web-page/.env.dist +0 -3
  46. vendor/weglot/weglot-php/examples/parsing-web-page/composer.json +0 -6
  47. vendor/weglot/weglot-php/examples/parsing-web-page/run.php +0 -39
  48. vendor/weglot/weglot-php/examples/simple-client-languages/.env.dist +0 -3
  49. vendor/weglot/weglot-php/examples/simple-client-languages/composer.json +0 -6
  50. vendor/weglot/weglot-php/examples/simple-client-languages/run.php +0 -21
  51. vendor/weglot/weglot-php/examples/simple-client-status/.env.dist +0 -3
  52. vendor/weglot/weglot-php/examples/simple-client-status/composer.json +0 -6
  53. vendor/weglot/weglot-php/examples/simple-client-status/run.php +0 -26
  54. vendor/weglot/weglot-php/examples/simple-client-translate/.env.dist +0 -3
  55. vendor/weglot/weglot-php/examples/simple-client-translate/composer.json +0 -6
  56. vendor/weglot/weglot-php/examples/simple-client-translate/run.php +0 -67
  57. vendor/weglot/weglot-php/src/Client/Client.php +12 -3
  58. vendor/weglot/weglot-php/src/Client/Endpoint/CdnTranslate.php +6 -16
  59. vendor/weglot/weglot-php/src/Client/Endpoint/LanguagesList.php +4 -2
  60. vendor/weglot/weglot-php/src/Parser/Formatter/CustomSwitchersFormatter.php +101 -0
  61. vendor/weglot/weglot-php/src/Parser/Parser.php +34 -7
  62. vendor/weglot/weglot-php/src/Util/Url.php +28 -15
  63. vendor/weglot/weglot-php/tests/_support/AcceptanceTester.php +0 -26
  64. vendor/weglot/weglot-php/tests/_support/FunctionalTester.php +0 -26
  65. vendor/weglot/weglot-php/tests/_support/Helper/Acceptance.php +0 -9
  66. vendor/weglot/weglot-php/tests/_support/Helper/Functional.php +0 -9
  67. vendor/weglot/weglot-php/tests/_support/Helper/Unit.php +0 -9
  68. vendor/weglot/weglot-php/tests/_support/UnitTester.php +0 -26
  69. vendor/weglot/weglot-php/tests/acceptance.suite.yml +0 -12
  70. vendor/weglot/weglot-php/tests/functional.suite.yml +0 -12
  71. vendor/weglot/weglot-php/tests/unit.suite.yml +0 -14
  72. vendor/weglot/weglot-php/tests/unit/Client/ClientCachingTest.php +0 -84
  73. vendor/weglot/weglot-php/tests/unit/Client/ClientTest.php +0 -78
  74. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/CachedTranslateTest.php +0 -122
  75. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/LanguagesTest.php +0 -69
  76. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/StatusTest.php +0 -42
  77. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/TranslateTest.php +0 -93
  78. vendor/weglot/weglot-php/tests/unit/Parser/Check/Dom/MetaContentTest.php +0 -84
  79. vendor/weglot/weglot-php/tests/unit/Parser/ParserTest.php +0 -138
  80. vendor/weglot/weglot-php/tests/unit/Util/JsonLdTest.php +0 -76
  81. vendor/weglot/weglot-php/tests/unit/Util/RegexTest.php +0 -85
  82. vendor/weglot/weglot-php/tests/unit/Util/UrlTest.php +0 -436
  83. weglot.php +2 -2
composer.json CHANGED
@@ -22,7 +22,7 @@
22
  }
23
  ],
24
  "require": {
25
- "weglot/weglot-php": "^1.1",
26
  "gmulti/morphism-php": "^0.3.0"
27
  },
28
  "repositories": [
@@ -38,7 +38,8 @@
38
  "roave/security-advisories": "dev-master",
39
  "phpseclib/phpseclib": "^2.0",
40
  "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
41
- "automattic/vipwpcs": "^2.2"
 
42
  },
43
  "scripts": {
44
  "post-install-cmd": [
22
  }
23
  ],
24
  "require": {
25
+ "weglot/weglot-php": "^1.3",
26
  "gmulti/morphism-php": "^0.3.0"
27
  },
28
  "repositories": [
38
  "roave/security-advisories": "dev-master",
39
  "phpseclib/phpseclib": "^2.0",
40
  "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
41
+ "automattic/vipwpcs": "^2.2",
42
+ "yoast/phpunit-polyfills": "^1.0"
43
  },
44
  "scripts": {
45
  "post-install-cmd": [
languages/weglot-fr_FR.po CHANGED
@@ -322,7 +322,7 @@ msgid ""
322
  "On the Business plan, you can choose 3 languages. If you need more, "
323
  "please %1$supgrade your plan%2$s."
324
  msgstr ""
325
- "Avec le plan Business, vous pouvez choisir cinq langues. Si vous avez besoin "
326
  "de plus, veuillez %1$smettre à niveau votre plan%2$s."
327
 
328
  #: templates/admin/pages/tabs/settings.php:162
322
  "On the Business plan, you can choose 3 languages. If you need more, "
323
  "please %1$supgrade your plan%2$s."
324
  msgstr ""
325
+ "Avec le plan Business, vous pouvez choisir trois langues. Si vous avez besoin "
326
  "de plus, veuillez %1$smettre à niveau votre plan%2$s."
327
 
328
  #: templates/admin/pages/tabs/settings.php:162
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: remyb92, gmulti, wysija, wpr0ck, glx77
3
  Tags: translate, multilingual, language, translation, localization, multilingual SEO, languages, translator, website translation, multilanguage, international, traduction
4
  Requires at least: 4.5
5
- Tested up to: 5.8
6
  Requires PHP: 5.6
7
  Stable tag: 3.4
8
  License: GPLv2 or later
@@ -210,14 +210,16 @@ See changelog for upgrade changes.
210
 
211
  == Changelog ==
212
 
213
- = 3.4 (15/09/2021) =
214
- * Add: All 404 pages are excluded from translation if you exclude /404 in the Weglot dashboard
215
- * Improved performance: Files for multilingual compatibility with other plugins are only called when necessary
216
- * Bugfix: Autoswitch feature now works with custom languages
217
- * Bugfix: Password reset link in translated emails now works
218
- * Bugfix: WooCommerce emails are now translated when using custom languages
219
- * Bugfix: Fixed warning in 404 styles.css.map
220
- * Bugfix: Autoswitch doesn't redirect when visitor comes from an external link from now on
 
 
221
 
222
  = Older versions =
223
 
2
  Contributors: remyb92, gmulti, wysija, wpr0ck, glx77
3
  Tags: translate, multilingual, language, translation, localization, multilingual SEO, languages, translator, website translation, multilanguage, international, traduction
4
  Requires at least: 4.5
5
+ Tested up to: 5.9
6
  Requires PHP: 5.6
7
  Stable tag: 3.4
8
  License: GPLv2 or later
210
 
211
  == Changelog ==
212
 
213
+ = 3.5 (07/12/2021) =
214
+
215
+ * Add: Autoswitch work on all page not only on homepage
216
+ * Add: Exclude url doesn't generate redirection
217
+ * Add: Add switcher from switcher editor
218
+ * Add: Call API from cdn to translate
219
+ * Add: Limited call API for deactivate account
220
+ * Bugfix: Problem with gform and multisite
221
+ * Bugfix: Fix hreflang generation with Cyrillic url
222
+ * Bugfix: Weglot search option now works even if we're not on a main_query
223
 
224
  = Older versions =
225
 
src/actions/admin/class-options-weglot.php CHANGED
@@ -84,6 +84,7 @@ class Options_Weglot implements Hooks_Interface_Weglot {
84
 
85
  $tab = $_GET[ 'tab' ]; //phpcs:ignore
86
  $options = $_POST[ WEGLOT_SLUG ]; //phpcs:ignore
 
87
  $options_bdd = $this->option_services->get_options_bdd_v3();
88
 
89
  switch ( $tab ) {
@@ -92,7 +93,7 @@ class Options_Weglot implements Hooks_Interface_Weglot {
92
  $options = $this->sanitize_options_settings( $options, $has_first_settings );
93
  $response = $this->option_services->save_options_to_weglot( $options, $has_first_settings );
94
 
95
- if ( $response['success'] && is_array($response['result']) ) {
96
  delete_transient( 'weglot_cache_cdn' );
97
 
98
  $api_key_private = $this->option_services->get_api_key_private();
@@ -119,14 +120,14 @@ class Options_Weglot implements Hooks_Interface_Weglot {
119
  update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key_private' ), $options['api_key_private'] );
120
  update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key' ), $response['result']['api_key'] );
121
 
122
- //get menu options
123
  $options_menu = $this->option_services->get_option( 'menu_switcher' );
124
- if(!empty($options_menu)){
125
- foreach ($options_menu as $key => $menu){
126
- if($options['custom_settings']['button_style']['is_dropdown'] == true){
127
- $options_menu[$key]['dropdown'] = 1;
128
- }else{
129
- $options_menu[$key]['dropdown'] = 0;
130
  }
131
  }
132
  }
@@ -174,10 +175,11 @@ class Options_Weglot implements Hooks_Interface_Weglot {
174
  public function sanitize_options_settings( $options, $has_first_settings = false ) {
175
  $user_info = $this->user_api_services->get_user_info( $options['api_key_private'] );
176
  $plans = $this->user_api_services->get_plans();
 
177
 
178
- // Limit language
179
  $limit = 30;
180
- if(isset($user_info['languages_limit'])){
181
  $limit = $user_info['languages_limit'];
182
  }
183
  $options['languages'] = array_splice( $options['languages'], 0, $limit );
@@ -212,12 +214,14 @@ class Options_Weglot implements Hooks_Interface_Weglot {
212
  array_walk_recursive(
213
  $options['excluded_blocks'],
214
  function ( &$element ) {
215
- //We remove unwanted backslashes
216
  $element = stripslashes( $element );
217
  }
218
  );
219
  }
220
-
 
 
221
  return $options;
222
  }
223
  }
84
 
85
  $tab = $_GET[ 'tab' ]; //phpcs:ignore
86
  $options = $_POST[ WEGLOT_SLUG ]; //phpcs:ignore
87
+
88
  $options_bdd = $this->option_services->get_options_bdd_v3();
89
 
90
  switch ( $tab ) {
93
  $options = $this->sanitize_options_settings( $options, $has_first_settings );
94
  $response = $this->option_services->save_options_to_weglot( $options, $has_first_settings );
95
 
96
+ if ( $response['success'] && is_array( $response['result'] ) ) {
97
  delete_transient( 'weglot_cache_cdn' );
98
 
99
  $api_key_private = $this->option_services->get_api_key_private();
120
  update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key_private' ), $options['api_key_private'] );
121
  update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key' ), $response['result']['api_key'] );
122
 
123
+ // get menu options.
124
  $options_menu = $this->option_services->get_option( 'menu_switcher' );
125
+ if ( ! empty( $options_menu ) ) {
126
+ foreach ( $options_menu as $key => $menu ) {
127
+ if ( $options['custom_settings']['button_style']['is_dropdown'] ) {
128
+ $options_menu[ $key ]['dropdown'] = 1;
129
+ } else {
130
+ $options_menu[ $key ]['dropdown'] = 0;
131
  }
132
  }
133
  }
175
  public function sanitize_options_settings( $options, $has_first_settings = false ) {
176
  $user_info = $this->user_api_services->get_user_info( $options['api_key_private'] );
177
  $plans = $this->user_api_services->get_plans();
178
+ $switchers = $this->option_services->get_switchers_editor_button();
179
 
180
+ // Limit language.
181
  $limit = 30;
182
+ if ( isset( $user_info['languages_limit'] ) ) {
183
  $limit = $user_info['languages_limit'];
184
  }
185
  $options['languages'] = array_splice( $options['languages'], 0, $limit );
214
  array_walk_recursive(
215
  $options['excluded_blocks'],
216
  function ( &$element ) {
217
+ // We remove unwanted backslashes.
218
  $element = stripslashes( $element );
219
  }
220
  );
221
  }
222
+ foreach ( $switchers as $switcher ) {
223
+ $options['custom_settings']['switchers'][] = $switcher;
224
+ }
225
  return $options;
226
  }
227
  }
src/actions/front/class-front-enqueue-weglot.php CHANGED
@@ -66,5 +66,6 @@ class Front_Enqueue_Weglot implements Hooks_Interface_Weglot {
66
 
67
  wp_add_inline_style( 'weglot-css', $this->option_services->get_flag_css() );
68
  wp_add_inline_style( 'weglot-css', $this->option_services->get_css_custom_inline() );
 
69
  }
70
  }
66
 
67
  wp_add_inline_style( 'weglot-css', $this->option_services->get_flag_css() );
68
  wp_add_inline_style( 'weglot-css', $this->option_services->get_css_custom_inline() );
69
+ wp_add_inline_style( 'weglot-css', $this->option_services->get_switcher_editor_css() );
70
  }
71
  }
src/actions/front/class-front-menu-weglot.php CHANGED
@@ -61,8 +61,9 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
61
  return;
62
  }
63
 
 
64
  add_filter( 'wp_get_nav_menu_items', array( $this, 'weglot_wp_get_nav_menu_items' ), 20 );
65
- add_filter( 'nav_menu_link_attributes', array( $this, 'add_nav_menu_link_attributes' ), 10, 2 );
66
  add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ) );
67
  }
68
 
@@ -72,18 +73,8 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
72
  * @return array
73
  */
74
  public function weglot_wp_get_nav_menu_items( $items ) {
75
- if ( ! $this->request_url_services->is_eligible_url() ) {
76
- foreach ( $items as $key => $item ) {
77
- if ( 'weglot-switcher' !== $item->post_name ) {
78
- continue;
79
- }
80
- unset( $items[ $key ] );
81
- }
82
-
83
- return $items;
84
- }
85
 
86
- // Prevent customizer
87
  if ( doing_action( 'customize_register' ) ) {
88
  return $items;
89
  }
@@ -138,7 +129,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
138
  continue;
139
  }
140
 
141
- $link_button = $this->request_url_services->get_weglot_url()->getForLanguage( $language );
142
  if ( ! $link_button ) {
143
  continue;
144
  }
@@ -153,15 +144,15 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
153
  $add_classes[] = $language->getInternalCode();
154
  }
155
 
156
- if ( $language === $this->language_services->get_original_language() &&
157
- strpos( $link_button, 'no_lredirect' ) === false && // If not exist
158
- ( is_home() || is_front_page() )
159
- && $this->option_services->get_option( 'auto_redirect' )
160
- ) { // Only for homepage
161
  if( strpos($link_button, '?') !== false ) {
162
- $link_button = str_replace('?' , '?no_lredirect=true&' , $link_button);
163
  } else {
164
- $link_button .= '?no_lredirect=true';
165
  }
166
  }
167
 
@@ -249,22 +240,16 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
249
  /**
250
  * @since 2.0
251
  * @version 2.4.0
252
- * @see nav_menu_link_attributes
253
  * @param array $attrs
254
  * @param object $item
255
  * @return array
256
  */
257
- public function add_nav_menu_link_attributes( $attrs, $item ) {
258
  $str = 'weglot-switcher';
259
  if ( strpos( $item->post_name, $str ) !== false ) {
260
- if ( ! $this->request_url_services->is_eligible_url() ) {
261
- $attrs['style'] = 'display:none';
262
- return $attrs;
263
- }
264
-
265
  $attrs['data-wg-notranslate'] = 'true';
266
  }
267
-
268
  return $attrs;
269
  }
270
  }
61
  return;
62
  }
63
 
64
+
65
  add_filter( 'wp_get_nav_menu_items', array( $this, 'weglot_wp_get_nav_menu_items' ), 20 );
66
+ add_filter( 'nav_menu_link_attributes', array( $this, 'add_nav_menu_link_attributes_atts' ), 10, 3 );
67
  add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ) );
68
  }
69
 
73
  * @return array
74
  */
75
  public function weglot_wp_get_nav_menu_items( $items ) {
 
 
 
 
 
 
 
 
 
 
76
 
77
+ // Prevent customizer.
78
  if ( doing_action( 'customize_register' ) ) {
79
  return $items;
80
  }
129
  continue;
130
  }
131
 
132
+ $link_button = $this->request_url_services->get_weglot_url()->getForLanguage( $language, true );
133
  if ( ! $link_button ) {
134
  continue;
135
  }
144
  $add_classes[] = $language->getInternalCode();
145
  }
146
 
147
+
148
+
149
+ if ( $this->option_services->get_option( 'auto_redirect' )
150
+ ) {
151
+ $isOrig = $language === $this->language_services->get_original_language() ? "true":"false";
152
  if( strpos($link_button, '?') !== false ) {
153
+ $link_button = str_replace('?' , "?wg-choose-original=$isOrig&" , $link_button);
154
  } else {
155
+ $link_button .= "?wg-choose-original=$isOrig";
156
  }
157
  }
158
 
240
  /**
241
  * @since 2.0
242
  * @version 2.4.0
243
+ * @see nav_menu_link_attributes_atts
244
  * @param array $attrs
245
  * @param object $item
246
  * @return array
247
  */
248
+ public function add_nav_menu_link_attributes_atts( $attrs, $item, $args ) {
249
  $str = 'weglot-switcher';
250
  if ( strpos( $item->post_name, $str ) !== false ) {
 
 
 
 
 
251
  $attrs['data-wg-notranslate'] = 'true';
252
  }
 
253
  return $attrs;
254
  }
255
  }
src/actions/front/class-search-weglot.php CHANGED
@@ -73,7 +73,7 @@ class Search_Weglot implements Hooks_Interface_Weglot {
73
  * @return void
74
  */
75
  public function pre_get_posts_translate( $query ) {
76
- if ( ! $query->is_search() || ! $query->is_main_query() ) {
77
  return;
78
  }
79
 
73
  * @return void
74
  */
75
  public function pre_get_posts_translate( $query ) {
76
+ if ( ! $query->is_search() ) {
77
  return;
78
  }
79
 
src/actions/front/class-shortcode-weglot.php CHANGED
@@ -41,10 +41,6 @@ class Shortcode_Weglot {
41
  * @return string
42
  */
43
  public function weglot_switcher_callback() {
44
- if ( ! $this->request_url_services->is_eligible_url() ) {
45
- return '';
46
- }
47
-
48
  return $this->button_services->get_html( 'weglot-shortcode' ); //phpcs:ignore
49
  }
50
  }
41
  * @return string
42
  */
43
  public function weglot_switcher_callback() {
 
 
 
 
44
  return $this->button_services->get_html( 'weglot-shortcode' ); //phpcs:ignore
45
  }
46
  }
src/actions/front/class-translate-page-weglot.php CHANGED
@@ -78,7 +78,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
78
  * @since 2.0
79
  */
80
  public function hooks() {
81
- if ( Helper_Is_Admin::is_wp_admin() ) {
82
  return;
83
  }
84
 
@@ -156,18 +156,12 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
156
  }
157
  }
158
 
159
- // URL not eligible.
160
- if ( ! $this->request_url_services->is_eligible_url() ) {
161
- return;
162
- }
163
-
164
  $active_translation = apply_filters( 'weglot_active_translation_before_process', true );
165
 
166
  if ( ! $active_translation ) {
167
  return;
168
  }
169
 
170
- $this->redirect_services->verify_no_redirect();
171
  $this->check_need_to_redirect();
172
 
173
  do_action( 'weglot_init_before_translate_page' );
@@ -184,6 +178,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
184
 
185
  $file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/content.html' );
186
 
 
187
  if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
188
  $this->translate_services->set_original_language( $this->language_services->get_original_language() );
189
  $this->translate_services->set_current_language( $this->request_url_services->get_current_language() );
@@ -200,11 +195,15 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
200
  * @since 2.0
201
  */
202
  public function check_need_to_redirect() {
 
203
  if (
204
  ! wp_doing_ajax() && // no ajax.
205
- $this->request_url_services->get_weglot_url()->getPath() === '/' && // front_page.
206
- ! $this->redirect_services->get_no_redirect() && // No force redirect.
207
- ! Server::detectBot( $_SERVER ) !== BotType::OTHER && //phpcs:ignore
 
 
 
208
  $this->option_services->get_option( 'auto_redirect' ) // have option redirect.
209
  ) {
210
  $this->redirect_services->auto_redirect();
@@ -222,17 +221,13 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
222
  // We initialize the URL here for the first time, the current language might be wrong in case of ajax with the language in a referer because at this time wp_doing_ajax is always false.
223
  $this->current_language = $this->request_url_services->get_current_language();
224
 
 
 
 
225
  if ( $original_language === $this->current_language ) {
226
  return;
227
  }
228
 
229
- // If we are not in the original language, but the URL is not available in the current language, we redirect to original.
230
- if ( ! $this->request_url_services->get_weglot_url()->getForLanguage( $this->current_language )
231
- && ! strpos( $this->request_url_services->get_weglot_url()->getForLanguage( $this->language_services->get_original_language() ), 'wp-comments-post.php' ) !== false ) {
232
- wp_redirect( $this->request_url_services->get_weglot_url()->getForLanguage( $this->language_services->get_original_language() ), 301 );
233
- exit;
234
- }
235
-
236
  // //If we receive a not translated slug we return a 301. For example if we have /fr/products but should have /fr/produits we should redirect to /fr/produits.
237
  if ( $this->request_url_services->get_weglot_url()->getRedirect() !== null ) {
238
  $redirect_to = $this->request_url_services->get_weglot_url()->getRedirect();
78
  * @since 2.0
79
  */
80
  public function hooks() {
81
+ if ( Helper_Is_Admin::is_wp_admin() || 'wp-login.php' === $GLOBALS['pagenow'] ) {
82
  return;
83
  }
84
 
156
  }
157
  }
158
 
 
 
 
 
 
159
  $active_translation = apply_filters( 'weglot_active_translation_before_process', true );
160
 
161
  if ( ! $active_translation ) {
162
  return;
163
  }
164
 
 
165
  $this->check_need_to_redirect();
166
 
167
  do_action( 'weglot_init_before_translate_page' );
178
 
179
  $file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/content.html' );
180
 
181
+
182
  if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
183
  $this->translate_services->set_original_language( $this->language_services->get_original_language() );
184
  $this->translate_services->set_current_language( $this->request_url_services->get_current_language() );
195
  * @since 2.0
196
  */
197
  public function check_need_to_redirect() {
198
+ $only_home = apply_filters('weglot_autoredirect_only_home' , false);
199
  if (
200
  ! wp_doing_ajax() && // no ajax.
201
+ ! is_rest() &&
202
+ ! Helper_Is_Admin::is_wp_admin() &&
203
+ $this->language_services->get_original_language() === $this->request_url_services->get_current_language() &&
204
+ ! isset( $_COOKIE['WG_CHOOSE_ORIGINAL'] ) && // No force redirect.
205
+ Server::detectBot( $_SERVER ) === BotType::HUMAN && //phpcs:ignore
206
+ ( !$only_home || ( $only_home && $this->request_url_services->get_weglot_url()->getPath() === '/' ) ) && // front_page.
207
  $this->option_services->get_option( 'auto_redirect' ) // have option redirect.
208
  ) {
209
  $this->redirect_services->auto_redirect();
221
  // We initialize the URL here for the first time, the current language might be wrong in case of ajax with the language in a referer because at this time wp_doing_ajax is always false.
222
  $this->current_language = $this->request_url_services->get_current_language();
223
 
224
+ // If the URL has a GET parameter wg-choose-original we need to set / unset the cookie and redirect.
225
+ $this->redirect_services->verify_no_redirect();
226
+
227
  if ( $original_language === $this->current_language ) {
228
  return;
229
  }
230
 
 
 
 
 
 
 
 
231
  // //If we receive a not translated slug we return a 301. For example if we have /fr/products but should have /fr/produits we should redirect to /fr/produits.
232
  if ( $this->request_url_services->get_weglot_url()->getRedirect() !== null ) {
233
  $redirect_to = $this->request_url_services->get_weglot_url()->getRedirect();
src/helpers/class-helper-api.php CHANGED
@@ -14,6 +14,8 @@ abstract class Helper_API {
14
 
15
  const API_BASE = 'https://api.weglot.com';
16
  const API_BASE_STAGING = 'https://api.weglot.dev';
 
 
17
  const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
18
 
19
  /**
14
 
15
  const API_BASE = 'https://api.weglot.com';
16
  const API_BASE_STAGING = 'https://api.weglot.dev';
17
+ const API_CDN_BASE = 'https://cdn-api-weglot.com';
18
+ const API_CDN_BASE_STAGING = 'https://cdn-api-weglot.dev';
19
  const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
20
 
21
  /**
src/helpers/class-helper-filter-url-weglot.php CHANGED
@@ -24,10 +24,11 @@ abstract class Helper_Filter_Url_Weglot {
24
  public static function filter_url_lambda( $url ) {
25
  $request_url_service = weglot_get_request_url_service();
26
  $replaced_url = $request_url_service->create_url_object( $url )->getForLanguage( $request_url_service->get_current_language() );
27
- if($replaced_url)
28
  return $replaced_url;
29
- else
30
  return $url;
 
31
  }
32
 
33
  /**
24
  public static function filter_url_lambda( $url ) {
25
  $request_url_service = weglot_get_request_url_service();
26
  $replaced_url = $request_url_service->create_url_object( $url )->getForLanguage( $request_url_service->get_current_language() );
27
+ if ( $replaced_url ) {
28
  return $replaced_url;
29
+ } else {
30
  return $url;
31
+ }
32
  }
33
 
34
  /**
src/models/class-schema-option-v3.php CHANGED
@@ -106,6 +106,9 @@ class Schema_Option_V3 {
106
  'flag_css' => 'flag_css',
107
  'menu_switcher' => 'menu_switcher',
108
  'active_wc_reload' => 'active_wc_reload',
 
 
 
109
  );
110
 
111
  return $schema;
106
  'flag_css' => 'flag_css',
107
  'menu_switcher' => 'menu_switcher',
108
  'active_wc_reload' => 'active_wc_reload',
109
+ 'versions' => 'versions',
110
+ 'slugTranslation' => 'versions.slugTranslation',
111
+ 'translation' => 'versions.translation',
112
  );
113
 
114
  return $schema;
src/services/class-button-service-weglot.php CHANGED
@@ -46,13 +46,21 @@ class Button_Service_Weglot {
46
  }
47
 
48
  /**
 
 
 
49
  * @since 2.3.0
50
  * @version 3.0.0
51
- * @return string
52
  */
53
- public function get_flag_class() {
54
- $type_flags = $this->option_services->get_option_button( 'type_flags' );
55
- $with_flags = $this->option_services->get_option_button( 'with_flags' );
 
 
 
 
 
 
56
 
57
  $flag_class = $with_flags ? 'weglot-flags ' : '';
58
  $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
@@ -64,49 +72,66 @@ class Button_Service_Weglot {
64
  }
65
 
66
  /**
67
- * @since 2.3.0
68
- * @version 3.0.0
69
  * @param LanguageEntry $language_entry
 
 
70
  * @return string
 
 
71
  */
72
- public function get_name_with_language_entry( $language_entry ) {
73
- if ( $this->option_services->get_option_button( 'with_name' ) ) {
74
- $name = ( $this->option_services->get_option( 'is_fullname' ) ) ? $language_entry->getLocalName() : strtoupper( $language_entry->getExternalCode() );
 
 
 
 
 
 
 
75
  } else {
76
- $name = '';
77
- remove_filter( 'the_title', 'twenty_twenty_one_post_title' );
 
 
 
 
 
78
  }
79
 
80
  return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
81
  }
82
 
83
  /**
 
 
 
84
  * @since 2.3.0
85
  * @version 3.0.0
86
- * @return string
87
  */
88
- public function get_class_dropdown() {
89
- $is_dropdown = $this->option_services->get_option_button( 'is_dropdown' );
90
- $class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
 
 
 
 
91
 
92
  return apply_filters( 'weglot_get_class_dropdown', $class );
93
  }
94
 
95
 
96
-
97
  /**
98
  * Get html button switcher
99
  *
100
- * @since 2.0
101
- * @version 2.3.1
102
- * @return string
103
  * @param string $add_class
 
 
 
 
 
104
  */
105
- public function get_html( $add_class = '' ) {
106
-
107
- if ( apply_filters( 'weglot_view_button_html', ! $this->request_url_services->is_eligible_url() ) ) {
108
- return '';
109
- }
110
 
111
  $weglot_url = $this->request_url_services->get_weglot_url();
112
  $amp_regex = $this->amp_services->get_regex( true );
@@ -116,15 +141,15 @@ class Button_Service_Weglot {
116
  $add_class .= ' weglot-invert';
117
  }
118
 
119
- $flag_class = $this->get_flag_class();
120
- $class_aside = $this->get_class_dropdown();
121
 
122
- $button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
123
  $button_html .= sprintf( '<aside data-wg-notranslate class="country-selector %s">', $class_aside . $add_class );
124
 
125
- $name = $this->get_name_with_language_entry( $current_language );
126
 
127
- $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . wp_rand( 1, 1000 );
128
  $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li weglot-lang weglot-language %s" data-code-language="%s" data-name-language="%s"><span class="wglanguage-name">%s</span></label>', esc_attr( $uniq_id ), esc_attr( $uniq_id ), esc_attr( $flag_class . $current_language->getInternalCode() ), esc_attr( $current_language->getInternalCode() ), esc_html( $name ), esc_html( $name ) );
129
 
130
  $button_html .= '<ul>';
@@ -135,23 +160,17 @@ class Button_Service_Weglot {
135
  continue;
136
  }
137
 
138
- $link_button = $this->request_url_services->get_weglot_url()->getForLanguage( $language );
139
- if ( ! $link_button ) {
140
- continue;
141
- }
142
 
143
  $button_html .= sprintf( '<li class="wg-li weglot-lang weglot-language %s" data-code-language="%s">', $flag_class . $language->getInternalCode(), $language->getInternalCode() );
144
- $name = $this->get_name_with_language_entry( $language );
145
-
146
- if ( $language === $this->language_services->get_original_language() &&
147
- strpos( $link_button, 'no_lredirect' ) === false && // If not exist
148
- ( is_home() || is_front_page() )
149
- && $this->option_services->get_option( 'auto_redirect' )
150
- ) { // Only for homepage
151
- if( strpos($link_button, '?') !== false ) {
152
- $link_button = str_replace('?' , '?no_lredirect=true' , $link_button);
153
  } else {
154
- $link_button .= '?no_lredirect=true';
155
  }
156
  }
157
 
@@ -170,4 +189,5 @@ class Button_Service_Weglot {
170
 
171
  return apply_filters( 'weglot_button_html', $button_html, $add_class );
172
  }
 
173
  }
46
  }
47
 
48
  /**
49
+ * @param array $switcher
50
+ *
51
+ * @return string
52
  * @since 2.3.0
53
  * @version 3.0.0
 
54
  */
55
+ public function get_flag_class( $switcher = [] ) {
56
+
57
+ if ( ! empty( $switcher['style'] ) ) {
58
+ $type_flags = $this->option_services->get_switcher_editor_option( 'flag_type', $switcher['style'] );
59
+ $with_flags = $this->option_services->get_switcher_editor_option( 'with_flags', $switcher['style']);
60
+ } else {
61
+ $type_flags = $this->option_services->get_option_button( 'type_flags' );
62
+ $with_flags = $this->option_services->get_option_button( 'with_flags' );
63
+ }
64
 
65
  $flag_class = $with_flags ? 'weglot-flags ' : '';
66
  $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
72
  }
73
 
74
  /**
 
 
75
  * @param LanguageEntry $language_entry
76
+ * @param array $switcher
77
+ *
78
  * @return string
79
+ * @version 3.0.0
80
+ * @since 2.3.0
81
  */
82
+ public function get_name_with_language_entry( $language_entry, array $switcher = [] ) {
83
+
84
+ if ( ! empty( $switcher['style'] ) ) {
85
+ $with_name = $this->option_services->get_switcher_editor_option( 'with_name', $switcher['style'] );
86
+ if ( $with_name ) {
87
+ $name = ( $this->option_services->get_switcher_editor_option( 'full_name', $switcher['style'] ) ) ? $language_entry->getLocalName() : strtoupper( $language_entry->getExternalCode() );
88
+ } else {
89
+ $name = '';
90
+ remove_filter( 'the_title', 'twenty_twenty_one_post_title' );
91
+ }
92
  } else {
93
+ $with_name = $this->option_services->get_option_button( 'with_name' );
94
+ if ( $with_name ) {
95
+ $name = ( $this->option_services->get_option( 'is_fullname' ) ) ? $language_entry->getLocalName() : strtoupper( $language_entry->getExternalCode() );
96
+ } else {
97
+ $name = '';
98
+ remove_filter( 'the_title', 'twenty_twenty_one_post_title' );
99
+ }
100
  }
101
 
102
  return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
103
  }
104
 
105
  /**
106
+ * @param array $switcher
107
+ *
108
+ * @return string
109
  * @since 2.3.0
110
  * @version 3.0.0
 
111
  */
112
+ public function get_class_dropdown( $switcher = [] ) {
113
+ if ( ! empty( $switcher['style'] ) ) {
114
+ $is_dropdown = $this->option_services->get_switcher_editor_option( 'is_dropdown', $switcher['style'] );
115
+ } else {
116
+ $is_dropdown = $this->option_services->get_option_button( 'is_dropdown' );
117
+ }
118
+ $class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
119
 
120
  return apply_filters( 'weglot_get_class_dropdown', $class );
121
  }
122
 
123
 
 
124
  /**
125
  * Get html button switcher
126
  *
 
 
 
127
  * @param string $add_class
128
+ * @param array $switcher
129
+ *
130
+ * @return string
131
+ * @version 2.3.1
132
+ * @since 2.0
133
  */
134
+ public function get_html( $add_class = '', $switcher = [] ) {
 
 
 
 
135
 
136
  $weglot_url = $this->request_url_services->get_weglot_url();
137
  $amp_regex = $this->amp_services->get_regex( true );
141
  $add_class .= ' weglot-invert';
142
  }
143
 
144
+ $flag_class = $this->get_flag_class( $switcher );
145
+ $class_aside = $this->get_class_dropdown( $switcher );
146
 
147
+ $button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
148
  $button_html .= sprintf( '<aside data-wg-notranslate class="country-selector %s">', $class_aside . $add_class );
149
 
150
+ $name = $this->get_name_with_language_entry( $current_language, $switcher );
151
 
152
+ $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . wp_rand( 1, 1000 );
153
  $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li weglot-lang weglot-language %s" data-code-language="%s" data-name-language="%s"><span class="wglanguage-name">%s</span></label>', esc_attr( $uniq_id ), esc_attr( $uniq_id ), esc_attr( $flag_class . $current_language->getInternalCode() ), esc_attr( $current_language->getInternalCode() ), esc_html( $name ), esc_html( $name ) );
154
 
155
  $button_html .= '<ul>';
160
  continue;
161
  }
162
 
163
+ $link_button = $this->request_url_services->get_weglot_url()->getForLanguage( $language, true );
 
 
 
164
 
165
  $button_html .= sprintf( '<li class="wg-li weglot-lang weglot-language %s" data-code-language="%s">', $flag_class . $language->getInternalCode(), $language->getInternalCode() );
166
+ $name = $this->get_name_with_language_entry( $language, $switcher );
167
+
168
+ if ( $this->option_services->get_option( 'auto_redirect' ) ) {
169
+ $is_orig = $language === $this->language_services->get_original_language() ? 'true' : 'false';
170
+ if ( strpos( $link_button, '?' ) !== false ) {
171
+ $link_button = str_replace( '?', "?wg-choose-original=$is_orig&", $link_button );
 
 
 
172
  } else {
173
+ $link_button .= "?wg-choose-original=$is_orig";
174
  }
175
  }
176
 
189
 
190
  return apply_filters( 'weglot_button_html', $button_html, $add_class );
191
  }
192
+
193
  }
src/services/class-generate-switcher-service-weglot.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace WeglotWP\Services;
4
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
@@ -40,10 +42,11 @@ class Generate_Switcher_Service_Weglot {
40
  }
41
 
42
  /**
43
- * @since 2.3.0
44
- *
45
  * @param string $dom
 
46
  * @return string
 
 
47
  */
48
  public function replace_div_id( $dom ) {
49
  if ( strpos( $dom, '<div id="weglot_here"></div>' ) === false ) {
@@ -57,27 +60,28 @@ class Generate_Switcher_Service_Weglot {
57
  }
58
 
59
  /**
60
- * @since 2.3.0
61
- * @version 3.0.0
62
  * @param string $dom
 
63
  * @return string
 
 
64
  */
65
  public function check_weglot_menu( $dom ) {
66
  return apply_filters( 'weglot_replace_weglot_menu', $dom );
67
  }
68
 
69
  /**
70
- * @since 2.3.0
71
- *
72
  * @param string $dom
 
73
  * @return string
 
74
  */
75
  public function render_default_button( $dom ) {
76
  if ( strpos( $dom, 'weglot-language' ) !== false ) {
77
  return $dom;
78
  }
79
 
80
- // Place the button if not in the page
81
  $button_html = $this->button_services->get_html( 'weglot-default' );
82
  $dom = ( strpos( $dom, '</body>' ) !== false ) ? str_replace( '</body>', $button_html . ' </body>', $dom ) : str_replace( '</footer>', $button_html . ' </footer>', $dom );
83
 
@@ -85,15 +89,71 @@ class Generate_Switcher_Service_Weglot {
85
  }
86
 
87
  /**
 
 
 
 
88
  * @since 2.3.0
89
- * @param string $dom
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  * @return string
 
91
  */
92
  public function generate_switcher_from_dom( $dom ) {
93
  $dom = $this->replace_div_id( $dom );
94
  $dom = $this->check_weglot_menu( $dom );
95
- $dom = $this->render_default_button( $dom );
96
 
 
 
 
 
 
 
97
  return apply_filters( 'weglot_generate_switcher_from_dom', $dom );
98
  }
99
  }
2
 
3
  namespace WeglotWP\Services;
4
 
5
+ use Weglot\Parser\Formatter\CustomSwitchersFormatter;
6
+
7
  if ( ! defined( 'ABSPATH' ) ) {
8
  exit;
9
  }
42
  }
43
 
44
  /**
 
 
45
  * @param string $dom
46
+ *
47
  * @return string
48
+ * @since 2.3.0
49
+ *
50
  */
51
  public function replace_div_id( $dom ) {
52
  if ( strpos( $dom, '<div id="weglot_here"></div>' ) === false ) {
60
  }
61
 
62
  /**
 
 
63
  * @param string $dom
64
+ *
65
  * @return string
66
+ * @since 2.3.0
67
+ * @version 3.0.0
68
  */
69
  public function check_weglot_menu( $dom ) {
70
  return apply_filters( 'weglot_replace_weglot_menu', $dom );
71
  }
72
 
73
  /**
 
 
74
  * @param string $dom
75
+ *
76
  * @return string
77
+ * @since 2.3.0
78
  */
79
  public function render_default_button( $dom ) {
80
  if ( strpos( $dom, 'weglot-language' ) !== false ) {
81
  return $dom;
82
  }
83
 
84
+ // Place the button if not in the page.
85
  $button_html = $this->button_services->get_html( 'weglot-default' );
86
  $dom = ( strpos( $dom, '</body>' ) !== false ) ? str_replace( '</body>', $button_html . ' </body>', $dom ) : str_replace( '</footer>', $button_html . ' </footer>', $dom );
87
 
89
  }
90
 
91
  /**
92
+ * @param string $dom the final HTML.
93
+ * @param array $switchers the array of switchers from settings.
94
+ *
95
+ * @return string
96
  * @since 2.3.0
97
+ */
98
+ public function render_switcher_editor_button( $dom, $switchers ) {
99
+
100
+ $original_language = $this->language_services->get_original_language()->getInternalCode();
101
+ $current_language = $this->request_url_services->get_current_language()->getInternalCode();
102
+
103
+ // In original language, as we don't use the PHP lib, we have not yet placed the custom switchers in the DOM so we need to use simple DOM here.
104
+ if ( $original_language === $current_language || ! $this->request_url_services->is_eligible_url() ) {
105
+ // simple_html_dom.
106
+ $dom = \WGSimpleHtmlDom\str_get_html(
107
+ $dom,
108
+ true,
109
+ true,
110
+ WG_DEFAULT_TARGET_CHARSET,
111
+ false
112
+ );
113
+
114
+ $custom_switchers = new CustomSwitchersFormatter( $dom, $switchers );
115
+ $dom = $custom_switchers->getDom();
116
+ $dom = $dom->save();
117
+ }
118
+
119
+ // Place the button if not in the page.
120
+ $find_location = false;
121
+ foreach ( $switchers as $switcher ) {
122
+
123
+ $button_html = $this->button_services->get_html( 'weglot-custom-switcher', $switcher );
124
+ $location = $this->option_services->get_switcher_editor_option( 'location', $switcher );
125
+
126
+ if ( ! empty( $location ) ) {
127
+ $key = $location['target'] . ( ! empty( $location['sibling'] ) ? ' ' . $location['sibling'] : '' );
128
+ if ( strpos( $dom, '<div data-wg-position="' . $key . '"></div>' ) !== false ) {
129
+ $dom = str_replace( '<div data-wg-position="' . $key . '"></div>', $button_html, $dom );
130
+ $find_location = true;
131
+ }
132
+ }
133
+ }
134
+ if ( ! $find_location ) {
135
+ return false;
136
+ }
137
+
138
+ return apply_filters( 'weglot_render_switcher_editor_button', $dom );
139
+ }
140
+
141
+ /**
142
+ * @param string $dom the final HTML.
143
+ *
144
  * @return string
145
+ * @since 2.3.0
146
  */
147
  public function generate_switcher_from_dom( $dom ) {
148
  $dom = $this->replace_div_id( $dom );
149
  $dom = $this->check_weglot_menu( $dom );
 
150
 
151
+ // check if custom switcher(s) exist in settings otherwise return default switcher.
152
+ if ( ! empty( $this->option_services->get_switchers_editor_button() ) ) {
153
+ $dom_with_switchers = $this->render_switcher_editor_button( $dom, $this->option_services->get_switchers_editor_button() );
154
+ }
155
+
156
+ $dom = ! empty( $dom_with_switchers ) ? $dom_with_switchers : $this->render_default_button( $dom );
157
  return apply_filters( 'weglot_generate_switcher_from_dom', $dom );
158
  }
159
  }
src/services/class-href-lang-service-weglot.php CHANGED
@@ -37,7 +37,9 @@ class Href_Lang_Service_Weglot {
37
  $urls = $this->request_url_services->get_weglot_url()->getAllUrls();
38
 
39
  foreach ( $urls as $url ) {
40
- $render .= '<link rel="alternate" href="' . esc_url( $url['url'] ) . '" hreflang="' . $url['language']->getExternalCode() . '"/>' . "\n";
 
 
41
  }
42
 
43
  return apply_filters( 'weglot_href_lang', $render );
37
  $urls = $this->request_url_services->get_weglot_url()->getAllUrls();
38
 
39
  foreach ( $urls as $url ) {
40
+ if ( ! $url['excluded'] ) {
41
+ $render .= '<link rel="alternate" href="' . esc_url( $url['url'] ) . '" hreflang="' . $url['language']->getExternalCode() . '"/>' . "\n";
42
+ }
43
  }
44
 
45
  return apply_filters( 'weglot_href_lang', $render );
src/services/class-option-service-weglot.php CHANGED
@@ -28,6 +28,8 @@ class Option_Service_Weglot {
28
  protected $options_from_api = null;
29
  protected $slugs_from_api = null;
30
 
 
 
31
  /**
32
  * @var array
33
  */
@@ -51,6 +53,9 @@ class Option_Service_Weglot {
51
  'with_flags' => true,
52
  'flag_type' => Helper_Flag_Type::RECTANGLE_MAT,
53
  'custom_css' => '',
 
 
 
54
  ),
55
  'rtl_ltr_style' => '',
56
  'active_wc_reload' => true,
@@ -59,6 +64,7 @@ class Option_Service_Weglot {
59
  'allowed' => true,
60
  'has_first_settings' => true,
61
  'show_box_first_settings' => false,
 
62
  );
63
 
64
  /**
@@ -99,6 +105,9 @@ class Option_Service_Weglot {
99
  * @since 3.0.0
100
  */
101
  protected function get_options_from_cdn_with_api_key( $api_key ) {
 
 
 
102
  if ( $this->options_cdn ) {
103
  return array(
104
  'success' => true,
@@ -112,6 +121,9 @@ class Option_Service_Weglot {
112
  $options = get_transient( 'weglot_cache_cdn', false );
113
  if ( $options ) {
114
  $this->options_cdn = $options;
 
 
 
115
 
116
  return array(
117
  'success' => true,
@@ -134,10 +146,16 @@ class Option_Service_Weglot {
134
  if ( is_wp_error( $response ) ) {
135
  $response = $this->get_options_from_api_with_api_key( $this->get_api_key_private() );
136
  $body = $response['result'];
137
- } else {
 
 
 
 
 
138
  $body = json_decode( $response['body'], true );
139
  set_transient( 'weglot_cache_cdn', $body, apply_filters( 'weglot_get_options_from_cdn_cache_duration', 300 ) );
140
  }
 
141
  $this->options_cdn = $body;
142
 
143
  return array(
@@ -300,6 +318,7 @@ class Option_Service_Weglot {
300
  $options_v2 = get_option( WEGLOT_SLUG );
301
 
302
  if ( $options_v2 ) {
 
303
  if ( array_key_exists( 'api_key', $options_v2 ) ) {
304
  $options_v2['api_key_private'] = $options_v2['api_key'];
305
  }
@@ -332,6 +351,20 @@ class Option_Service_Weglot {
332
  return apply_filters( 'weglot_get_api_key', $options['api_key'] );
333
  }
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  /**
336
  * @param bool $compatibility
337
  *
@@ -371,6 +404,11 @@ class Option_Service_Weglot {
371
  return $this->get_options_from_v2();
372
  }
373
  }
 
 
 
 
 
374
  $options = $response['result'];
375
  if ( $api_key_private ) {
376
  $options['api_key_private'] = $api_key_private;
@@ -393,7 +431,7 @@ class Option_Service_Weglot {
393
  $slugs = $this->get_slugs_from_cache_with_api_key( $api_key_private, $destinations_languages );
394
  }
395
  }
396
- if ( isset( $slugs ) ) {
397
  $options['custom_urls'] = $this->array_merge_recursive_ex( $options['custom_urls'], $slugs );
398
  }
399
 
@@ -522,6 +560,45 @@ class Option_Service_Weglot {
522
  return $options[ $key ];
523
  }
524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  /**
526
  * @return array
527
  * @throws Exception
@@ -538,7 +615,7 @@ class Option_Service_Weglot {
538
  $exclude_blocks[] = '#wpadminbar';
539
 
540
  // Weglot Switcher.
541
- $exclude_blocks[] = '.menu-item-weglot';
542
 
543
  // Material Icons.
544
  $exclude_blocks[] = '.material-icons';
@@ -715,4 +792,21 @@ class Option_Service_Weglot {
715
 
716
  return $options[ $key ];
717
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
718
  }
28
  protected $options_from_api = null;
29
  protected $slugs_from_api = null;
30
 
31
+ const NO_OPTIONS = 'OPTIONS_NOT_FOUND';
32
+
33
  /**
34
  * @var array
35
  */
53
  'with_flags' => true,
54
  'flag_type' => Helper_Flag_Type::RECTANGLE_MAT,
55
  'custom_css' => '',
56
+ ),
57
+ 'switchers' => array(
58
+
59
  ),
60
  'rtl_ltr_style' => '',
61
  'active_wc_reload' => true,
64
  'allowed' => true,
65
  'has_first_settings' => true,
66
  'show_box_first_settings' => false,
67
+ 'version' => 1,
68
  );
69
 
70
  /**
105
  * @since 3.0.0
106
  */
107
  protected function get_options_from_cdn_with_api_key( $api_key ) {
108
+ if ( $this->options_cdn === self::NO_OPTIONS ) {
109
+ return array( 'success' => false );
110
+ }
111
  if ( $this->options_cdn ) {
112
  return array(
113
  'success' => true,
121
  $options = get_transient( 'weglot_cache_cdn', false );
122
  if ( $options ) {
123
  $this->options_cdn = $options;
124
+ if ( $this->options_cdn === self::NO_OPTIONS ) {
125
+ return array( 'success' => false );
126
+ }
127
 
128
  return array(
129
  'success' => true,
146
  if ( is_wp_error( $response ) ) {
147
  $response = $this->get_options_from_api_with_api_key( $this->get_api_key_private() );
148
  $body = $response['result'];
149
+ } elseif ( wp_remote_retrieve_response_code( $response ) === 403 ) {
150
+ set_transient( 'weglot_cache_cdn', self::NO_OPTIONS, 0 );
151
+ $this->options_cdn = self::NO_OPTIONS;
152
+ return array( 'success' => false );
153
+ }
154
+ else {
155
  $body = json_decode( $response['body'], true );
156
  set_transient( 'weglot_cache_cdn', $body, apply_filters( 'weglot_get_options_from_cdn_cache_duration', 300 ) );
157
  }
158
+
159
  $this->options_cdn = $body;
160
 
161
  return array(
318
  $options_v2 = get_option( WEGLOT_SLUG );
319
 
320
  if ( $options_v2 ) {
321
+
322
  if ( array_key_exists( 'api_key', $options_v2 ) ) {
323
  $options_v2['api_key_private'] = $options_v2['api_key'];
324
  }
351
  return apply_filters( 'weglot_get_api_key', $options['api_key'] );
352
  }
353
 
354
+ /**
355
+ *
356
+ * @return string
357
+ * @throws Exception
358
+ * @since 3.0.0
359
+ */
360
+ public function get_version() {
361
+ $options = $this->get_options();
362
+ if ( ! isset( $options['versions']['translation'] ) ) {
363
+ return apply_filters( 'weglot_get_version', 1 );
364
+ }
365
+ return apply_filters( 'weglot_get_version', $options['versions']['translation'] );
366
+ }
367
+
368
  /**
369
  * @param bool $compatibility
370
  *
404
  return $this->get_options_from_v2();
405
  }
406
  }
407
+
408
+ if( ! array_key_exists('result', $response)) {
409
+ return $this->get_options_from_v2();
410
+ }
411
+
412
  $options = $response['result'];
413
  if ( $api_key_private ) {
414
  $options['api_key_private'] = $api_key_private;
431
  $slugs = $this->get_slugs_from_cache_with_api_key( $api_key_private, $destinations_languages );
432
  }
433
  }
434
+ if ( isset( $slugs ) && is_array( $slugs ) ) {
435
  $options['custom_urls'] = $this->array_merge_recursive_ex( $options['custom_urls'], $slugs );
436
  }
437
 
560
  return $options[ $key ];
561
  }
562
 
563
+ /**
564
+ *
565
+ * Returns the array "switchers" from the custom_settings or an empty array
566
+ *
567
+ * @return array|boolean|int
568
+ * @since 3.0.0
569
+ */
570
+ public function get_switchers_editor_button() {
571
+ $options = $this->get_options();
572
+ if (
573
+ array_key_exists( 'custom_settings', $options ) &&
574
+ is_array( $options['custom_settings'] ) &&
575
+ ! empty( $options['custom_settings']['switchers'] )
576
+ ) {
577
+ return $options['custom_settings']['switchers'];
578
+ }
579
+ return array();
580
+ }
581
+
582
+ /**
583
+ * @param string $key
584
+ * @param array $switcher
585
+ *
586
+ * @return string|boolean|int
587
+ * @throws Exception
588
+ * @since 3.0.0
589
+ */
590
+ public function get_switcher_editor_option( $key, $switcher ) {
591
+
592
+ if ( ! empty( $switcher ) ) {
593
+ if (
594
+ array_key_exists( $key, $switcher )
595
+ ) {
596
+ return $switcher[ $key ];
597
+ }
598
+ }
599
+ return null;
600
+ }
601
+
602
  /**
603
  * @return array
604
  * @throws Exception
615
  $exclude_blocks[] = '#wpadminbar';
616
 
617
  // Weglot Switcher.
618
+ $exclude_blocks[] = '.menu-item-weglot a';
619
 
620
  // Material Icons.
621
  $exclude_blocks[] = '.material-icons';
792
 
793
  return $options[ $key ];
794
  }
795
+
796
+ /**
797
+ * @return string
798
+ * @throws Exception
799
+ * @since 2.0
800
+ */
801
+ public function get_switcher_editor_css() {
802
+ $switcher_editor_css = '';
803
+ if(!empty($this->get_switchers_editor_button())){
804
+ foreach ($this->get_switchers_editor_button() as $switcher){
805
+ if(!empty($switcher['style']['custom_css'])){
806
+ $switcher_editor_css .= $switcher['style']['custom_css'];
807
+ }
808
+ }
809
+ }
810
+ return $switcher_editor_css;
811
+ }
812
  }
src/services/class-parser-service-weglot.php CHANGED
@@ -49,6 +49,7 @@ class Parser_Service_Weglot {
49
  */
50
  public function get_client() {
51
  $api_key = $this->option_services->get_api_key( true );
 
52
  $translation_engine = $this->option_services->get_translation_engine();
53
  if ( ! $translation_engine || empty( $translation_engine ) ) {
54
  $translation_engine = 2;
@@ -56,6 +57,7 @@ class Parser_Service_Weglot {
56
 
57
  $client = new Client(
58
  $api_key,
 
59
  $translation_engine,
60
  array(
61
  'host' => Helper_API::get_api_url(),
@@ -73,9 +75,10 @@ class Parser_Service_Weglot {
73
  * @version 2.2.2
74
  */
75
  public function get_parser() {
76
- $exclude_blocks = $this->option_services->get_exclude_blocks();
77
 
78
- $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
 
 
79
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
80
  $config = new ServerConfigProvider();
81
  }
@@ -85,7 +88,8 @@ class Parser_Service_Weglot {
85
  }
86
 
87
  $client = $this->get_client();
88
- $parser = new Parser( $client, $config, $exclude_blocks );
 
89
  $parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
90
  $parser->getRegexCheckerProvider()->addCheckers( $this->regex_checkers_services->get_regex_checkers() );
91
  $ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
49
  */
50
  public function get_client() {
51
  $api_key = $this->option_services->get_api_key( true );
52
+ $version = $this->option_services->get_version();
53
  $translation_engine = $this->option_services->get_translation_engine();
54
  if ( ! $translation_engine || empty( $translation_engine ) ) {
55
  $translation_engine = 2;
57
 
58
  $client = new Client(
59
  $api_key,
60
+ $version,
61
  $translation_engine,
62
  array(
63
  'host' => Helper_API::get_api_url(),
75
  * @version 2.2.2
76
  */
77
  public function get_parser() {
 
78
 
79
+ $exclude_blocks = $this->option_services->get_exclude_blocks();
80
+ $custom_switchers = $this->option_services->get_switchers_editor_button();
81
+ $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
82
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
83
  $config = new ServerConfigProvider();
84
  }
88
  }
89
 
90
  $client = $this->get_client();
91
+ $parser = new Parser( $client, $config, $exclude_blocks, $custom_switchers );
92
+
93
  $parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
94
  $parser->getRegexCheckerProvider()->addCheckers( $this->regex_checkers_services->get_regex_checkers() );
95
  $ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
src/services/class-redirect-service-weglot.php CHANGED
@@ -114,6 +114,8 @@ class Redirect_Service_Weglot {
114
  */
115
  public function get_best_available_language( $navigator_languages, $available_languages ) {
116
 
 
 
117
  if ( ! empty( $navigator_languages ) ) {
118
  $destination_languages_external = array_map( 'strtolower', $available_languages );
119
  foreach ( $navigator_languages as $navigator_language ) {
@@ -150,13 +152,6 @@ class Redirect_Service_Weglot {
150
  */
151
  public function auto_redirect() {
152
 
153
- // prevent redirect if referer not come from extern
154
- if ( ( isset( $_SERVER['HTTP_REFERER'] ) && ! empty( $_SERVER['HTTP_REFERER'] ) && isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST']) ) ) { //phpcs:ignore
155
- if ( strtolower( wp_parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) ) == strtolower( $_SERVER['HTTP_HOST'] ) ) { //phpcs:ignore
156
- return;
157
- }
158
- }
159
-
160
  if ( ! isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) && ! isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { //phpcs:ignore
161
  return;
162
  }
@@ -167,10 +162,9 @@ class Redirect_Service_Weglot {
167
  $best_external_language = $this->get_best_available_language( $navigator_languages, $destination_languages_external );
168
  $best_language = $this->language_services->get_language_from_external( $best_external_language );
169
 
170
-
171
  // Redirect using the best language.
172
- if ( isset( $best_language ) && $this->language_services->get_original_language() === $this->request_url_services->get_current_language() ) {
173
- $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $best_language ) );
174
  header( "Location: $url_auto_redirect", true, 302 );
175
  exit();
176
  }
@@ -178,11 +172,10 @@ class Redirect_Service_Weglot {
178
  // If there is no best language, we redirect using the auto switch fallback if there is one in the options.
179
  if ( ! isset( $best_language ) &&
180
  ! in_array( $this->language_services->get_original_language()->getExternalCode(), $navigator_languages ) &&
181
- $this->language_services->get_original_language() === $this->request_url_services->get_current_language() &&
182
  $this->option_services->get_option( 'autoswitch_fallback' ) !== null
183
  ) {
184
  $fallback_language = $this->language_services->get_language_from_internal( $this->option_services->get_option( 'autoswitch_fallback' ) );
185
- $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $fallback_language ) );
186
  header( "Location: $url_auto_redirect", true, 302 );
187
  exit();
188
  }
@@ -194,19 +187,30 @@ class Redirect_Service_Weglot {
194
  *
195
  */
196
  public function verify_no_redirect() {
197
- if ( strpos( $this->request_url_services->get_weglot_url()->getUrl(), '?no_lredirect=true' ) === false ) {
198
- return;
199
- }
200
-
201
- $this->no_redirect = true;
202
- if ( isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore
203
- $_SERVER['REQUEST_URI'] = str_replace( '?no_lredirect=true', '?', str_replace(
204
- '?no_lredirect=true&',
205
- '?',
206
- $_SERVER['REQUEST_URI'] //phpcs:ignore
207
- ) );
208
-
209
- $this->request_url_services->init_weglot_url(); //We reset the URL as we removed the parameter from URL
 
 
 
 
 
 
 
 
 
 
 
210
  }
211
  }
212
  }
114
  */
115
  public function get_best_available_language( $navigator_languages, $available_languages ) {
116
 
117
+ // We add the original in the list of available languages.
118
+ $available_languages[] = $this->language_services->get_original_language()->getExternalCode();
119
  if ( ! empty( $navigator_languages ) ) {
120
  $destination_languages_external = array_map( 'strtolower', $available_languages );
121
  foreach ( $navigator_languages as $navigator_language ) {
152
  */
153
  public function auto_redirect() {
154
 
 
 
 
 
 
 
 
155
  if ( ! isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) && ! isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { //phpcs:ignore
156
  return;
157
  }
162
  $best_external_language = $this->get_best_available_language( $navigator_languages, $destination_languages_external );
163
  $best_language = $this->language_services->get_language_from_external( $best_external_language );
164
 
 
165
  // Redirect using the best language.
166
+ if ( isset( $best_language ) && $best_language !== $this->language_services->get_original_language() && $this->language_services->get_original_language() === $this->request_url_services->get_current_language() ) {
167
+ $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $best_language, true ) );
168
  header( "Location: $url_auto_redirect", true, 302 );
169
  exit();
170
  }
172
  // If there is no best language, we redirect using the auto switch fallback if there is one in the options.
173
  if ( ! isset( $best_language ) &&
174
  ! in_array( $this->language_services->get_original_language()->getExternalCode(), $navigator_languages ) &&
 
175
  $this->option_services->get_option( 'autoswitch_fallback' ) !== null
176
  ) {
177
  $fallback_language = $this->language_services->get_language_from_internal( $this->option_services->get_option( 'autoswitch_fallback' ) );
178
+ $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $fallback_language, true ) );
179
  header( "Location: $url_auto_redirect", true, 302 );
180
  exit();
181
  }
187
  *
188
  */
189
  public function verify_no_redirect() {
190
+ if ( isset ( $_GET["wg-choose-original"] ) ) { //phpcs:ignore
191
+ $wg_choose_original = $_GET["wg-choose-original"]; //phpcs:ignore
192
+ if ( 'true' === $wg_choose_original ) {
193
+ setcookie( "WG_CHOOSE_ORIGINAL", true, time() + 86400 * 2, '/' ); //phpcs:ignore
194
+ } elseif ( 'false' === $wg_choose_original ) {
195
+ setcookie( "WG_CHOOSE_ORIGINAL", null, - 1, '/' ); //phpcs:ignore
196
+ } else {
197
+ return;
198
+ }
199
+ if ( isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore
200
+
201
+ $_SERVER['REQUEST_URI'] = str_replace(
202
+ "?wg-choose-original=$wg_choose_original",
203
+ '',
204
+ str_replace(
205
+ "?wg-choose-original=$wg_choose_original&",
206
+ '?',
207
+ $_SERVER['REQUEST_URI'] //phpcs:ignore
208
+ )
209
+ );
210
+ $this->request_url_services->init_weglot_url(); // We reset the URL as we removed the parameter from URL.
211
+ header( 'Location:' . $this->request_url_services->get_weglot_url()->getUrl(), true, 302 );
212
+ exit();
213
+ }
214
  }
215
  }
216
  }
src/services/class-replace-link-service-weglot.php CHANGED
@@ -49,7 +49,7 @@ class Replace_Link_Service_Weglot {
49
  * @return string
50
  */
51
  public function replace_url( $url, $language ) {
52
- $replaced_url = $this->request_url_services->create_url_object( $url )->getForLanguage( $language );
53
  if($replaced_url)
54
  return $replaced_url;
55
  else
49
  * @return string
50
  */
51
  public function replace_url( $url, $language ) {
52
+ $replaced_url = $this->request_url_services->create_url_object( $url )->getForLanguage( $language, true );
53
  if($replaced_url)
54
  return $replaced_url;
55
  else
src/services/class-replace-url-service-weglot.php CHANGED
@@ -54,6 +54,7 @@ class Replace_Url_Service_Weglot {
54
  * @return string
55
  */
56
  public function replace_link_in_dom( $dom ) {
 
57
  $data = Helper_Replace_Url_Weglot::get_replace_modify_link();
58
 
59
  foreach ( $data as $key => $value ) {
@@ -61,15 +62,35 @@ class Replace_Url_Service_Weglot {
61
  }
62
 
63
  $current_language = $this->request_url_services->get_current_language();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- if ( $current_language->getExternalCode() !== $current_language->getInternalCode() ) {
66
- $dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language->getExternalCode() . '$4 weglot-lang=$2' . $current_language->getInternalCode() . '$4', $dom );
 
 
 
67
  } else {
68
- $dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language->getExternalCode() . '$4', $dom );
 
 
 
 
69
  }
70
-
71
- $dom = preg_replace( '/property="og:locale" content=(\"|\')(\S*)(\"|\')/', 'property="og:locale" content=$1' . $current_language->getExternalCode() . '$3', $dom );
72
-
73
  return apply_filters( 'weglot_replace_link', $dom );
74
  }
75
 
@@ -176,7 +197,6 @@ class Replace_Url_Service_Weglot {
176
  && strpos( $current_url, $admin_url ) === false
177
  && strpos( $current_url, 'wp-login' ) === false
178
  && ! $this->is_link_a_file( $current_url )
179
- && $this->request_url_services->is_eligible_url( $current_url )
180
  && strpos( $sometags, 'data-wg-notranslate' ) === false
181
  && strpos( $sometags2, 'data-wg-notranslate' ) === false
182
  );
54
  * @return string
55
  */
56
  public function replace_link_in_dom( $dom ) {
57
+
58
  $data = Helper_Replace_Url_Weglot::get_replace_modify_link();
59
 
60
  foreach ( $data as $key => $value ) {
62
  }
63
 
64
  $current_language = $this->request_url_services->get_current_language();
65
+ $current_url = $this->request_url_services->get_weglot_url();
66
+
67
+ if ( $current_url->getForLanguage( $current_language, false ) ) {
68
+ if ( $current_language->getExternalCode() !== $current_language->getInternalCode() ) {
69
+ $dom = preg_replace(
70
+ '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/',
71
+ '<html $1lang=$2' . $current_language->getExternalCode() . '$4 weglot-lang=$2' . $current_language->getInternalCode() . '$4',
72
+ $dom
73
+ );
74
+ } else {
75
+ $dom = preg_replace(
76
+ '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/',
77
+ '<html $1lang=$2' . $current_language->getExternalCode() . '$4',
78
+ $dom
79
+ );
80
+ }
81
 
82
+ $dom = preg_replace(
83
+ '/property="og:locale" content=(\"|\')(\S*)(\"|\')/',
84
+ 'property="og:locale" content=$1' . $current_language->getExternalCode() . '$3',
85
+ $dom
86
+ );
87
  } else {
88
+ $dom = preg_replace(
89
+ '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/',
90
+ '<html $1lang=$2$3$4 data-excluded-page="true"',
91
+ $dom
92
+ );
93
  }
 
 
 
94
  return apply_filters( 'weglot_replace_link', $dom );
95
  }
96
 
197
  && strpos( $current_url, $admin_url ) === false
198
  && strpos( $current_url, 'wp-login' ) === false
199
  && ! $this->is_link_a_file( $current_url )
 
200
  && strpos( $sometags, 'data-wg-notranslate' ) === false
201
  && strpos( $sometags2, 'data-wg-notranslate' ) === false
202
  );
src/services/class-request-url-service-weglot.php CHANGED
@@ -164,11 +164,13 @@ class Request_Url_Service_Weglot {
164
 
165
  /**
166
  * Returns true if the URL is translated in at least one language
 
167
  * @since 2.0
168
  * @param string $url
 
169
  * @return boolean
170
  */
171
- public function is_eligible_url( $url = null ) {
172
 
173
  if ( ! $url ) {
174
  $weglot_url = $this->get_weglot_url();
@@ -176,10 +178,13 @@ class Request_Url_Service_Weglot {
176
  $weglot_url = $this->create_url_object( $url );
177
  }
178
 
179
- if ( empty( $weglot_url->availableInLanguages() ) ) {
 
 
180
  return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
 
 
181
  }
182
- return apply_filters( 'weglot_is_eligible_url', true, $url );
183
  }
184
 
185
  /**
@@ -190,7 +195,7 @@ class Request_Url_Service_Weglot {
190
 
191
  public function url_to_relative( $url ) {
192
  if ( ( substr( $url, 0, 7 ) === 'http://' ) || ( substr( $url, 0, 8 ) === 'https://' ) ) {
193
- // the current link is an "absolute" URL - parse it to get just the path
194
  $parsed = wp_parse_url( $url );
195
  $path = isset( $parsed['path'] ) ? $parsed['path'] : '';
196
  $query = isset( $parsed['query'] ) ? '?' . $parsed['query'] : '';
164
 
165
  /**
166
  * Returns true if the URL is translated in at least one language
167
+ *
168
  * @since 2.0
169
  * @param string $url
170
+ * @param bool $even_excluded
171
  * @return boolean
172
  */
173
+ public function is_eligible_url( $url = null, $even_excluded = false ) {
174
 
175
  if ( ! $url ) {
176
  $weglot_url = $this->get_weglot_url();
178
  $weglot_url = $this->create_url_object( $url );
179
  }
180
 
181
+ if ( empty( $weglot_url->availableInLanguages( $even_excluded ) ) ) {
182
+ return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
183
+ } elseif ( ! $weglot_url->isTranslableInLanguage( $this->get_weglot_url()->getCurrentLanguage(), $even_excluded ) ) {
184
  return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
185
+ } else {
186
+ return apply_filters( 'weglot_is_eligible_url', true, $weglot_url );
187
  }
 
188
  }
189
 
190
  /**
195
 
196
  public function url_to_relative( $url ) {
197
  if ( ( substr( $url, 0, 7 ) === 'http://' ) || ( substr( $url, 0, 8 ) === 'https://' ) ) {
198
+ // the current link is an "absolute" URL - parse it to get just the path.
199
  $parsed = wp_parse_url( $url );
200
  $path = isset( $parsed['path'] ) ? $parsed['path'] : '';
201
  $query = isset( $parsed['query'] ) ? '?' . $parsed['query'] : '';
src/services/class-translate-service-weglot.php CHANGED
@@ -66,8 +66,8 @@ class Translate_Service_Weglot {
66
 
67
 
68
  /**
69
- * @since 2.3.0
70
  * @return void
 
71
  */
72
  public function weglot_translate() {
73
  ob_start( array( $this, 'weglot_treat_page' ) );
@@ -75,26 +75,31 @@ class Translate_Service_Weglot {
75
 
76
  /**
77
  * @param LanguageEntry $current_language
 
78
  * @return Translate_Service_Weglot
79
  * @since 2.3.0
80
  */
81
  public function set_current_language( $current_language ) {
82
  $this->current_language = $current_language->getInternalCode();
 
83
  return $this;
84
  }
85
 
86
  /**
87
  * @param LanguageEntry $original_language
 
88
  * @return Translate_Service_Weglot
89
  * @since 2.3.0
90
  */
91
  public function set_original_language( $original_language ) {
92
  $this->original_language = $original_language->getInternalCode();
 
93
  return $this;
94
  }
95
 
96
  /**
97
  * @param string $content
 
98
  * @return string
99
  */
100
  public function get_canonical_url_from_content( $content ) {
@@ -111,8 +116,41 @@ class Translate_Service_Weglot {
111
  }
112
  }
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  /**
115
  * @param string $content
 
116
  * @return string
117
  * @throws \Exception
118
  * @since 2.3.0
@@ -123,7 +161,7 @@ class Translate_Service_Weglot {
123
  return $content;
124
  }
125
  $this->set_original_language( $this->language_services->get_original_language() );
126
- $this->set_current_language( $this->request_url_services->get_current_language() ); // Need to reset
127
 
128
  // Choose type translate.
129
  $type = ( Helper_Json_Inline_Weglot::is_json( $content ) ) ? 'json' : 'html';
@@ -134,7 +172,12 @@ class Translate_Service_Weglot {
134
  $canonical = $this->get_canonical_url_from_content( $content );
135
 
136
  // No need to translate but prepare new dom with button.
137
- if ( $this->current_language === $this->original_language || ! $active_translation ) {
 
 
 
 
 
138
  return $this->weglot_render_dom( $content, $canonical );
139
  }
140
 
@@ -143,27 +186,19 @@ class Translate_Service_Weglot {
143
  try {
144
  switch ( $type ) {
145
  case 'json':
146
- $extraKeys = apply_filters( 'weglot_add_json_keys', array() );
147
- $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, $extraKeys );
148
  $translated_content = wp_json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
149
- $translated_content = apply_filters( 'weglot_json_treat_page', $translated_content );
150
- return $translated_content;
151
  case 'html':
152
- //if status code = 404 and /404 are in exlude url we don't translate content
153
- if(http_response_code() == 404){
154
- $excluded_urls = $this->option_services->get_exclude_urls();
155
- foreach ($excluded_urls as $url){
156
- if(in_array('^/404$', $url)){
157
- return $this->weglot_render_dom( $content, $canonical );
158
- }
159
- }
160
- }
161
-
162
- $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, [] , $canonical );
163
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
 
164
  return $this->weglot_render_dom( $translated_content, $canonical );
165
  default:
166
  $name_filter = sprintf( 'weglot_%s_treat_page', $type );
 
167
  return apply_filters( $name_filter, $content, $parser, $this->original_language, $this->current_language );
168
 
169
  }
@@ -175,6 +210,7 @@ class Translate_Service_Weglot {
175
  nocache_headers();
176
  $content .= '<!--Weglot error API : ' . $this->remove_comments( $e->getMessage() ) . '-->';
177
  }
 
178
  return $content;
179
  } catch ( \Exception $e ) {
180
  if ( 'json' !== $type ) {
@@ -184,6 +220,7 @@ class Translate_Service_Weglot {
184
  nocache_headers();
185
  $content .= '<!--Weglot error : ' . $this->remove_comments( $e->getMessage() ) . '-->';
186
  }
 
187
  return $content;
188
  }
189
  }
@@ -192,9 +229,10 @@ class Translate_Service_Weglot {
192
  /**
193
  * Remove comments from HTML.
194
  *
195
- * @since 2.3.0
196
  * @param string $html the HTML string.
 
197
  * @return string
 
198
  */
199
  private function remove_comments( $html ) {
200
  return preg_replace( '/<!--(.*)-->/Uis', '', $html );
@@ -204,9 +242,11 @@ class Translate_Service_Weglot {
204
  /**
205
  * Replace links and add switcher on the final HTML.
206
  *
207
- * @since 2.3.0
208
  * @param string $dom the final translated HTML.
 
 
209
  * @return string
 
210
  */
211
  public function weglot_render_dom( $dom, $canonical = '' ) {
212
  $dom = $this->generate_switcher_service->generate_switcher_from_dom( $dom );
@@ -218,11 +258,18 @@ class Translate_Service_Weglot {
218
 
219
  // Remove hreflangs if non canonical page.
220
  if ( '' !== $canonical ) {
 
221
  $current_url = $this->request_url_services->get_weglot_url();
222
  if ( $current_url->getForLanguage( $this->language_services->get_original_language() ) !== $canonical ) {
223
  $dom = preg_replace( '/<link rel="alternate" href=(\"|\')([^\s\>]+?)(\"|\') hreflang=(\"|\')([^\s\>]+?)(\"|\')\/>/', '', $dom );
224
  }
 
 
 
 
 
225
  }
 
226
  return apply_filters( 'weglot_render_dom', $dom );
227
  }
228
  }
66
 
67
 
68
  /**
 
69
  * @return void
70
+ * @since 2.3.0
71
  */
72
  public function weglot_translate() {
73
  ob_start( array( $this, 'weglot_treat_page' ) );
75
 
76
  /**
77
  * @param LanguageEntry $current_language
78
+ *
79
  * @return Translate_Service_Weglot
80
  * @since 2.3.0
81
  */
82
  public function set_current_language( $current_language ) {
83
  $this->current_language = $current_language->getInternalCode();
84
+
85
  return $this;
86
  }
87
 
88
  /**
89
  * @param LanguageEntry $original_language
90
+ *
91
  * @return Translate_Service_Weglot
92
  * @since 2.3.0
93
  */
94
  public function set_original_language( $original_language ) {
95
  $this->original_language = $original_language->getInternalCode();
96
+
97
  return $this;
98
  }
99
 
100
  /**
101
  * @param string $content
102
+ *
103
  * @return string
104
  */
105
  public function get_canonical_url_from_content( $content ) {
116
  }
117
  }
118
 
119
+ /**
120
+ * @return boolean
121
+ */
122
+ public function check_ajax_exclusion_before_treat() {
123
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
124
+ if ( ! $this->request_url_services->create_url_object( wp_get_referer() )->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
125
+ return true;
126
+ }
127
+ }
128
+
129
+ return false;
130
+ }
131
+
132
+ /**
133
+ * @return boolean
134
+ */
135
+ public function check_404_exclusion_before_treat() {
136
+
137
+ if ( http_response_code() == 404 ) {
138
+ $excluded_urls = $this->option_services->get_exclude_urls();
139
+ foreach ( $excluded_urls as $url ) {
140
+ if ( in_array( '^/404$', $url ) ) {
141
+ return true;
142
+ }
143
+ }
144
+
145
+ return false;
146
+ } else {
147
+ return false;
148
+ }
149
+ }
150
+
151
  /**
152
  * @param string $content
153
+ *
154
  * @return string
155
  * @throws \Exception
156
  * @since 2.3.0
161
  return $content;
162
  }
163
  $this->set_original_language( $this->language_services->get_original_language() );
164
+ $this->set_current_language( $this->request_url_services->get_current_language() ); // Need to reset.
165
 
166
  // Choose type translate.
167
  $type = ( Helper_Json_Inline_Weglot::is_json( $content ) ) ? 'json' : 'html';
172
  $canonical = $this->get_canonical_url_from_content( $content );
173
 
174
  // No need to translate but prepare new dom with button.
175
+ if (
176
+ $this->current_language === $this->original_language
177
+ || ! $active_translation
178
+ || $this->check_404_exclusion_before_treat()
179
+ || $this->check_ajax_exclusion_before_treat()
180
+ || ! $this->request_url_services->get_weglot_url()->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
181
  return $this->weglot_render_dom( $content, $canonical );
182
  }
183
 
186
  try {
187
  switch ( $type ) {
188
  case 'json':
189
+ $extra_keys = apply_filters( 'weglot_add_json_keys', array() );
190
+ $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, $extra_keys );
191
  $translated_content = wp_json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
192
+
193
+ return apply_filters( 'weglot_json_treat_page', $translated_content );
194
  case 'html':
195
+ $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, array(), $canonical );
 
 
 
 
 
 
 
 
 
 
196
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
197
+
198
  return $this->weglot_render_dom( $translated_content, $canonical );
199
  default:
200
  $name_filter = sprintf( 'weglot_%s_treat_page', $type );
201
+
202
  return apply_filters( $name_filter, $content, $parser, $this->original_language, $this->current_language );
203
 
204
  }
210
  nocache_headers();
211
  $content .= '<!--Weglot error API : ' . $this->remove_comments( $e->getMessage() ) . '-->';
212
  }
213
+
214
  return $content;
215
  } catch ( \Exception $e ) {
216
  if ( 'json' !== $type ) {
220
  nocache_headers();
221
  $content .= '<!--Weglot error : ' . $this->remove_comments( $e->getMessage() ) . '-->';
222
  }
223
+
224
  return $content;
225
  }
226
  }
229
  /**
230
  * Remove comments from HTML.
231
  *
 
232
  * @param string $html the HTML string.
233
+ *
234
  * @return string
235
+ * @since 2.3.0
236
  */
237
  private function remove_comments( $html ) {
238
  return preg_replace( '/<!--(.*)-->/Uis', '', $html );
242
  /**
243
  * Replace links and add switcher on the final HTML.
244
  *
 
245
  * @param string $dom the final translated HTML.
246
+ * @param string $canonical the canonical link.
247
+ *
248
  * @return string
249
+ * @since 2.3.0
250
  */
251
  public function weglot_render_dom( $dom, $canonical = '' ) {
252
  $dom = $this->generate_switcher_service->generate_switcher_from_dom( $dom );
258
 
259
  // Remove hreflangs if non canonical page.
260
  if ( '' !== $canonical ) {
261
+ $canonical = urldecode( $canonical );
262
  $current_url = $this->request_url_services->get_weglot_url();
263
  if ( $current_url->getForLanguage( $this->language_services->get_original_language() ) !== $canonical ) {
264
  $dom = preg_replace( '/<link rel="alternate" href=(\"|\')([^\s\>]+?)(\"|\') hreflang=(\"|\')([^\s\>]+?)(\"|\')\/>/', '', $dom );
265
  }
266
+
267
+ // update canonical if page excluded page.
268
+ if ( ! $current_url->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
269
+ $dom = preg_replace( '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', '<link rel="canonical" href="' . $current_url->getForLanguage( $this->language_services->get_original_language() ) . '"', $dom );
270
+ }
271
  }
272
+
273
  return apply_filters( 'weglot_render_dom', $dom );
274
  }
275
  }
src/third/gravityforms/class-gf-filter-urls.php CHANGED
@@ -55,7 +55,11 @@ class GF_Filter_Urls implements Hooks_Interface_Weglot {
55
  return $data;
56
  }
57
 
58
- $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_lambda( $data['redirect'] );
 
 
 
 
59
  return $data;
60
 
61
  }
55
  return $data;
56
  }
57
 
58
+ #todo change logic in multisite context
59
+ if(!is_multisite()){
60
+ $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_lambda( $data['redirect'] );
61
+ }
62
+
63
  return $data;
64
 
65
  }
src/third/woocommerce/class-wc-filter-urls-weglot.php CHANGED
@@ -76,7 +76,6 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
76
  * @since 2.6.0
77
  */
78
  add_filter( 'woocommerce_get_cart_page_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
79
-
80
  add_filter( 'woocommerce_get_endpoint_url', array( $this, 'weglot_woocommerce_get_endpoint_url' ), 10, 4 );
81
  }
82
 
76
  * @since 2.6.0
77
  */
78
  add_filter( 'woocommerce_get_cart_page_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
 
79
  add_filter( 'woocommerce_get_endpoint_url', array( $this, 'weglot_woocommerce_get_endpoint_url' ), 10, 4 );
80
  }
81
 
src/widgets/class-widget-selector-weglot.php CHANGED
@@ -37,9 +37,7 @@ class Widget_Selector_Weglot extends \WP_Widget {
37
  public function widget( $args, $instance ) {
38
  /** @var Request_Url_Service_Weglot $request_url_service */
39
  $request_url_service = weglot_get_service( 'Request_Url_Service_Weglot' );
40
- if ( ! $request_url_service->is_eligible_url() ) {
41
- return;
42
- }
43
  $title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
44
  $title = apply_filters( 'widget_title', $title );
45
 
37
  public function widget( $args, $instance ) {
38
  /** @var Request_Url_Service_Weglot $request_url_service */
39
  $request_url_service = weglot_get_service( 'Request_Url_Service_Weglot' );
40
+
 
 
41
  $title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
42
  $title = apply_filters( 'widget_title', $title );
43
 
templates/admin/pages/tabs/advanced.php CHANGED
@@ -11,37 +11,37 @@ use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
11
  use WeglotWP\Helpers\Helper_Excluded_Type;
12
 
13
  $options_available = [
14
- 'exclude_urls' => [
15
  'key' => 'exclude_urls',
16
  'label' => __( 'Exclusion URL', 'weglot' ),
17
  'description' => __( 'Add URL that you want to exclude from translations. You can use regular expression to match multiple URLs. ', 'weglot' ),
18
  ],
19
- 'exclude_blocks' => [
20
  'key' => 'exclude_blocks',
21
  'label' => __( 'Exclusion Blocks', 'weglot' ),
22
  'description' => __( 'Enter the CSS selector of blocks you don\'t want to translate (like a sidebar, a menu, a paragraph, etc...)', 'weglot' ),
23
  ],
24
- 'auto_redirect' => [
25
  'key' => 'auto_redirect',
26
  'label' => __( 'Auto redirection', 'weglot' ),
27
  'description' => __( 'Check if you want to redirect users based on their browser language.', 'weglot' ),
28
  ],
29
- 'email_translate' => [
30
  'key' => 'email_translate',
31
  'label' => __( 'Translate email', 'weglot' ),
32
  'description' => __( 'Check to translate all emails who use function wp_mail', 'weglot' ),
33
  ],
34
- 'translate_amp' => [
35
  'key' => 'translate_amp',
36
  'label' => __( 'Translate AMP', 'weglot' ),
37
  'description' => __( 'Translate AMP page', 'weglot' ),
38
  ],
39
- 'active_search' => [
40
  'key' => 'active_search',
41
  'label' => __( 'Search WordPress', 'weglot' ),
42
  'description' => __( 'Allow your users to search in the language they use.', 'weglot' ),
43
  ],
44
- 'private_mode' => [
45
  'key' => 'private_mode',
46
  'label' => __( 'Private mode', 'weglot' ),
47
  'description' => __( 'Check if your only want admin users to see the translations', 'weglot' ),
@@ -50,7 +50,7 @@ $options_available = [
50
  'key' => 'active_wc_reload',
51
  'label' => __( '[WooCommerce] : Prevent reload cart', 'weglot' ),
52
  'description' => __( 'You should only enable this option if you have translation errors on your cart widget.', 'weglot' ),
53
- ],
54
  ];
55
 
56
  ?>
@@ -68,7 +68,9 @@ $options_available = [
68
  <p class="sub-label"><?php echo esc_html( $options_available['exclude_urls']['description'] ); ?></p>
69
  </th>
70
  <td class="forminp forminp-text">
71
- <a class="btn btn-soft" href="https://dashboard.weglot.com/settings/exclusions" target="_blank"><span class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'Manage URL to exclude', 'weglot' ); ?></a>
 
 
72
  </td>
73
  </tr>
74
  <tr valign="top">
@@ -95,12 +97,14 @@ $options_available = [
95
  <span class="dashicons dashicons-minus"></span>
96
  </button>
97
  </div>
98
- <?php
99
  endforeach;
100
  endif;
101
  ?>
102
  </div>
103
- <button id="js-add-exclude-block" class="btn btn-soft"><span class="dashicons dashicons-plus-alt"></span> <?php esc_html_e( 'Add a block to exclude', 'weglot' ); ?></button>
 
 
104
  </td>
105
  </tr>
106
  </tbody>
@@ -110,70 +114,70 @@ $options_available = [
110
  <hr>
111
  <table class="form-table">
112
  <tbody>
113
- <tr valign="top">
114
- <th scope="row" class="titledesc">
115
- <label for="<?php echo esc_attr( $options_available['auto_redirect']['key'] ); ?>">
116
- <?php echo esc_html( $options_available['auto_redirect']['label'] ); ?>
117
- </label>
118
- </th>
119
- <td class="forminp forminp-text">
120
- <input
121
- name="<?php echo esc_attr( sprintf( '%s[auto_switch]', WEGLOT_SLUG ) ); ?>"
122
- id="<?php echo esc_attr( $options_available['auto_redirect']['key'] ); ?>"
123
- type="checkbox"
124
- <?php checked( $this->options[ $options_available['auto_redirect']['key'] ], 1 ); ?>
125
- >
126
- <p class="description"><?php echo esc_html( $options_available['auto_redirect']['description'] ); ?></p>
127
- </td>
128
- </tr>
129
- <tr valign="top">
130
- <th scope="row" class="titledesc">
131
- <label for="<?php echo esc_attr( $options_available['email_translate']['key'] ); ?>">
132
- <?php echo esc_html( $options_available['email_translate']['label'] ); ?>
133
- </label>
134
- </th>
135
- <td class="forminp forminp-text">
136
- <input
137
- name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_email]', WEGLOT_SLUG ) ); ?>"
138
- id="<?php echo esc_attr( $options_available['email_translate']['key'] ); ?>"
139
- type="checkbox"
140
- <?php checked( $this->options[ $options_available['email_translate']['key'] ], 1 ); ?>
141
- >
142
- <p class="description"><?php echo esc_html( $options_available['email_translate']['description'] ); ?></p>
143
- </td>
144
- </tr>
145
- <tr valign="top">
146
- <th scope="row" class="titledesc">
147
- <label for="<?php echo esc_attr( $options_available['translate_amp']['key'] ); ?>">
148
- <?php echo esc_html( $options_available['translate_amp']['label'] ); ?>
149
- </label>
150
- </th>
151
- <td class="forminp forminp-text">
152
- <input
153
- name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_amp]', WEGLOT_SLUG ) ); ?>"
154
- id="<?php echo esc_attr( $options_available['translate_amp']['key'] ); ?>"
155
- type="checkbox"
156
- <?php checked( $this->options[ $options_available['translate_amp']['key'] ], 1 ); ?>
157
- >
158
- <p class="description"><?php echo esc_html( $options_available['translate_amp']['description'] ); ?></p>
159
- </td>
160
- </tr>
161
- <tr valign="top">
162
- <th scope="row" class="titledesc">
163
- <label for="<?php echo esc_attr( $options_available['active_search']['key'] ); ?>">
164
- <?php echo esc_html( $options_available['active_search']['label'] ); ?>
165
- </label>
166
- </th>
167
- <td class="forminp forminp-text">
168
- <input
169
- name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_search]', WEGLOT_SLUG ) ); ?>"
170
- id="<?php echo esc_attr( $options_available['active_search']['key'] ); ?>"
171
- type="checkbox"
172
- <?php checked( $this->options[ $options_available['active_search']['key'] ], 1 ); ?>
173
- >
174
- <p class="description"><?php echo esc_html( $options_available['active_search']['description'] ); ?></p>
175
- </td>
176
- </tr>
177
  </tbody>
178
  </table>
179
 
@@ -183,7 +187,8 @@ $options_available = [
183
  name="<?php echo esc_attr( sprintf( '%s[excluded_paths][{KEY}][type]', WEGLOT_SLUG ) ); ?>"
184
  >
185
  <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $ex_type ) : ?>
186
- <option value="<?php echo esc_attr( $ex_type ); ?>"><?php echo esc_attr( Helper_Excluded_Type::get_label_type( $ex_type ) ); ?></option>
 
187
  <?php endforeach; ?>
188
  </select>
189
  <input
11
  use WeglotWP\Helpers\Helper_Excluded_Type;
12
 
13
  $options_available = [
14
+ 'exclude_urls' => [
15
  'key' => 'exclude_urls',
16
  'label' => __( 'Exclusion URL', 'weglot' ),
17
  'description' => __( 'Add URL that you want to exclude from translations. You can use regular expression to match multiple URLs. ', 'weglot' ),
18
  ],
19
+ 'exclude_blocks' => [
20
  'key' => 'exclude_blocks',
21
  'label' => __( 'Exclusion Blocks', 'weglot' ),
22
  'description' => __( 'Enter the CSS selector of blocks you don\'t want to translate (like a sidebar, a menu, a paragraph, etc...)', 'weglot' ),
23
  ],
24
+ 'auto_redirect' => [
25
  'key' => 'auto_redirect',
26
  'label' => __( 'Auto redirection', 'weglot' ),
27
  'description' => __( 'Check if you want to redirect users based on their browser language.', 'weglot' ),
28
  ],
29
+ 'email_translate' => [
30
  'key' => 'email_translate',
31
  'label' => __( 'Translate email', 'weglot' ),
32
  'description' => __( 'Check to translate all emails who use function wp_mail', 'weglot' ),
33
  ],
34
+ 'translate_amp' => [
35
  'key' => 'translate_amp',
36
  'label' => __( 'Translate AMP', 'weglot' ),
37
  'description' => __( 'Translate AMP page', 'weglot' ),
38
  ],
39
+ 'active_search' => [
40
  'key' => 'active_search',
41
  'label' => __( 'Search WordPress', 'weglot' ),
42
  'description' => __( 'Allow your users to search in the language they use.', 'weglot' ),
43
  ],
44
+ 'private_mode' => [
45
  'key' => 'private_mode',
46
  'label' => __( 'Private mode', 'weglot' ),
47
  'description' => __( 'Check if your only want admin users to see the translations', 'weglot' ),
50
  'key' => 'active_wc_reload',
51
  'label' => __( '[WooCommerce] : Prevent reload cart', 'weglot' ),
52
  'description' => __( 'You should only enable this option if you have translation errors on your cart widget.', 'weglot' ),
53
+ ]
54
  ];
55
 
56
  ?>
68
  <p class="sub-label"><?php echo esc_html( $options_available['exclude_urls']['description'] ); ?></p>
69
  </th>
70
  <td class="forminp forminp-text">
71
+ <a class="btn btn-soft" href="https://dashboard.weglot.com/settings/exclusions" target="_blank"><span
72
+ class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'Manage URL to exclude', 'weglot' ); ?>
73
+ </a>
74
  </td>
75
  </tr>
76
  <tr valign="top">
97
  <span class="dashicons dashicons-minus"></span>
98
  </button>
99
  </div>
100
+ <?php
101
  endforeach;
102
  endif;
103
  ?>
104
  </div>
105
+ <button id="js-add-exclude-block" class="btn btn-soft"><span
106
+ class="dashicons dashicons-plus-alt"></span> <?php esc_html_e( 'Add a block to exclude', 'weglot' ); ?>
107
+ </button>
108
  </td>
109
  </tr>
110
  </tbody>
114
  <hr>
115
  <table class="form-table">
116
  <tbody>
117
+ <tr valign="top">
118
+ <th scope="row" class="titledesc">
119
+ <label for="<?php echo esc_attr( $options_available['auto_redirect']['key'] ); ?>">
120
+ <?php echo esc_html( $options_available['auto_redirect']['label'] ); ?>
121
+ </label>
122
+ </th>
123
+ <td class="forminp forminp-text">
124
+ <input
125
+ name="<?php echo esc_attr( sprintf( '%s[auto_switch]', WEGLOT_SLUG ) ); ?>"
126
+ id="<?php echo esc_attr( $options_available['auto_redirect']['key'] ); ?>"
127
+ type="checkbox"
128
+ <?php checked( $this->options[ $options_available['auto_redirect']['key'] ], 1 ); ?>
129
+ >
130
+ <p class="description"><?php echo esc_html( $options_available['auto_redirect']['description'] ); ?></p>
131
+ </td>
132
+ </tr>
133
+ <tr valign="top">
134
+ <th scope="row" class="titledesc">
135
+ <label for="<?php echo esc_attr( $options_available['email_translate']['key'] ); ?>">
136
+ <?php echo esc_html( $options_available['email_translate']['label'] ); ?>
137
+ </label>
138
+ </th>
139
+ <td class="forminp forminp-text">
140
+ <input
141
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_email]', WEGLOT_SLUG ) ); ?>"
142
+ id="<?php echo esc_attr( $options_available['email_translate']['key'] ); ?>"
143
+ type="checkbox"
144
+ <?php checked( $this->options[ $options_available['email_translate']['key'] ], 1 ); ?>
145
+ >
146
+ <p class="description"><?php echo esc_html( $options_available['email_translate']['description'] ); ?></p>
147
+ </td>
148
+ </tr>
149
+ <tr valign="top">
150
+ <th scope="row" class="titledesc">
151
+ <label for="<?php echo esc_attr( $options_available['translate_amp']['key'] ); ?>">
152
+ <?php echo esc_html( $options_available['translate_amp']['label'] ); ?>
153
+ </label>
154
+ </th>
155
+ <td class="forminp forminp-text">
156
+ <input
157
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_amp]', WEGLOT_SLUG ) ); ?>"
158
+ id="<?php echo esc_attr( $options_available['translate_amp']['key'] ); ?>"
159
+ type="checkbox"
160
+ <?php checked( $this->options[ $options_available['translate_amp']['key'] ], 1 ); ?>
161
+ >
162
+ <p class="description"><?php echo esc_html( $options_available['translate_amp']['description'] ); ?></p>
163
+ </td>
164
+ </tr>
165
+ <tr valign="top">
166
+ <th scope="row" class="titledesc">
167
+ <label for="<?php echo esc_attr( $options_available['active_search']['key'] ); ?>">
168
+ <?php echo esc_html( $options_available['active_search']['label'] ); ?>
169
+ </label>
170
+ </th>
171
+ <td class="forminp forminp-text">
172
+ <input
173
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_search]', WEGLOT_SLUG ) ); ?>"
174
+ id="<?php echo esc_attr( $options_available['active_search']['key'] ); ?>"
175
+ type="checkbox"
176
+ <?php checked( $this->options[ $options_available['active_search']['key'] ], 1 ); ?>
177
+ >
178
+ <p class="description"><?php echo esc_html( $options_available['active_search']['description'] ); ?></p>
179
+ </td>
180
+ </tr>
181
  </tbody>
182
  </table>
183
 
187
  name="<?php echo esc_attr( sprintf( '%s[excluded_paths][{KEY}][type]', WEGLOT_SLUG ) ); ?>"
188
  >
189
  <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $ex_type ) : ?>
190
+ <option
191
+ value="<?php echo esc_attr( $ex_type ); ?>"><?php echo esc_attr( Helper_Excluded_Type::get_label_type( $ex_type ) ); ?></option>
192
  <?php endforeach; ?>
193
  </select>
194
  <input
templates/admin/pages/tabs/appearance.php CHANGED
@@ -40,17 +40,22 @@ $options_available = [
40
  'flag_css' => [
41
  'key' => 'flag_css',
42
  ],
 
 
 
 
 
43
  ];
44
 
45
-
46
-
47
  ?>
48
  <style id="weglot-css-flag-css"></style>
49
  <style id="weglot-css-inline"></style>
 
50
  <h3>
51
  <?php echo esc_html__( 'Language button design', 'weglot' ) . ' ' . esc_html__( '(Optional)', 'weglot' ); ?>
52
  </h3>
53
  <hr />
 
54
  <table class="form-table">
55
  <tbody>
56
  <tr valign="top">
@@ -273,7 +278,7 @@ $options_available = [
273
  </tr>
274
  </tbody>
275
  </table>
276
-
277
 
278
  <h3>
279
  <?php echo esc_html_e( 'Language button position', 'weglot' ) . ' ' . esc_html__( '(Optional)', 'weglot' ); ?>
@@ -309,6 +314,7 @@ $options_available = [
309
  </td>
310
  </tr>
311
  <?php endif; ?>
 
312
  <tr valign="top">
313
  <th scope="row"><?php esc_html_e( 'In menu?', 'weglot' ); ?></th>
314
  <td>
@@ -333,6 +339,21 @@ $options_available = [
333
  <?php esc_html_e( 'You can add the code &lt;div id=&quot;weglot_here&quot;&gt;&lt;/div&gt; wherever you want in the source code of your HTML page. The button will appear at this place.', 'weglot' ); ?>
334
  </td>
335
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  </table>
337
 
338
  <template id="li-button-tpl">
40
  'flag_css' => [
41
  'key' => 'flag_css',
42
  ],
43
+ 'switcher_editor' => [
44
+ 'key' => 'switcher_editor',
45
+ 'label' => __( 'Custom position?', 'weglot' ),
46
+ 'description' => __( 'You can place the button anywhere in your site using our switcher editor in your Weglot Dashboard', 'weglot' ),
47
+ ],
48
  ];
49
 
 
 
50
  ?>
51
  <style id="weglot-css-flag-css"></style>
52
  <style id="weglot-css-inline"></style>
53
+ <?php if ( empty( $this->option_services->get_switchers_editor_button() ) ) { ?>
54
  <h3>
55
  <?php echo esc_html__( 'Language button design', 'weglot' ) . ' ' . esc_html__( '(Optional)', 'weglot' ); ?>
56
  </h3>
57
  <hr />
58
+
59
  <table class="form-table">
60
  <tbody>
61
  <tr valign="top">
278
  </tr>
279
  </tbody>
280
  </table>
281
+ <?php } ?>
282
 
283
  <h3>
284
  <?php echo esc_html_e( 'Language button position', 'weglot' ) . ' ' . esc_html__( '(Optional)', 'weglot' ); ?>
314
  </td>
315
  </tr>
316
  <?php endif; ?>
317
+
318
  <tr valign="top">
319
  <th scope="row"><?php esc_html_e( 'In menu?', 'weglot' ); ?></th>
320
  <td>
339
  <?php esc_html_e( 'You can add the code &lt;div id=&quot;weglot_here&quot;&gt;&lt;/div&gt; wherever you want in the source code of your HTML page. The button will appear at this place.', 'weglot' ); ?>
340
  </td>
341
  </tr>
342
+
343
+ <tr valign="top">
344
+ <th scope="row" class="titledesc">
345
+ <label for="<?php echo esc_attr( $options_available['switcher_editor']['key'] ); ?>">
346
+ <?php echo esc_html( $options_available['switcher_editor']['label'] ); ?>
347
+ </label>
348
+ <p class="sub-label"><?php echo esc_html( $options_available['switcher_editor']['description'] ); ?></p>
349
+ </th>
350
+ <td class="forminp forminp-text">
351
+ <a class="btn btn-soft"
352
+ href="https://dashboard.weglot.com/settings/language-switcher/editor?url=<?php echo esc_url( get_home_url() ); ?>" target="_blank"><span
353
+ class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'Use switcher editor', 'weglot' ); ?>
354
+ </a>
355
+ </td>
356
+ </tr>
357
  </table>
358
 
359
  <template id="li-button-tpl">
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit65e5f51a63291647ab68debc39683336::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitf74286d2f9f463ba8f91c37ca7d71d21::getLoader();
vendor/composer/InstalledVersions.php CHANGED
@@ -30,7 +30,7 @@ private static $installed = array (
30
  'aliases' =>
31
  array (
32
  ),
33
- 'reference' => 'b3ace5ac887a72333f797353f3c57aaeab2c2692',
34
  'name' => 'weglot/translate-wordpress',
35
  ),
36
  'versions' =>
@@ -69,7 +69,7 @@ private static $installed = array (
69
  'aliases' =>
70
  array (
71
  ),
72
- 'reference' => 'b3ace5ac887a72333f797353f3c57aaeab2c2692',
73
  ),
74
  'weglot/translation-definitions' =>
75
  array (
@@ -82,12 +82,12 @@ private static $installed = array (
82
  ),
83
  'weglot/weglot-php' =>
84
  array (
85
- 'pretty_version' => '1.1.13',
86
- 'version' => '1.1.13.0',
87
  'aliases' =>
88
  array (
89
  ),
90
- 'reference' => '022336df150ebb01cecc80b035ec3556521f1c24',
91
  ),
92
  ),
93
  );
30
  'aliases' =>
31
  array (
32
  ),
33
+ 'reference' => '8a0ce8d7cbb4a77b2d322bc47f4e2b8a3b274e3d',
34
  'name' => 'weglot/translate-wordpress',
35
  ),
36
  'versions' =>
69
  'aliases' =>
70
  array (
71
  ),
72
+ 'reference' => '8a0ce8d7cbb4a77b2d322bc47f4e2b8a3b274e3d',
73
  ),
74
  'weglot/translation-definitions' =>
75
  array (
82
  ),
83
  'weglot/weglot-php' =>
84
  array (
85
+ 'pretty_version' => '1.3',
86
+ 'version' => '1.3.0.0',
87
  'aliases' =>
88
  array (
89
  ),
90
+ 'reference' => 'e2b5413fbf38380167867f085bc24a1796c94fd5',
91
  ),
92
  ),
93
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit65e5f51a63291647ab68debc39683336
6
  {
7
  private static $loader;
8
 
@@ -24,15 +24,15 @@ class ComposerAutoloaderInit65e5f51a63291647ab68debc39683336
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
- spl_autoload_register(array('ComposerAutoloaderInit65e5f51a63291647ab68debc39683336', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
- spl_autoload_unregister(array('ComposerAutoloaderInit65e5f51a63291647ab68debc39683336', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
- call_user_func(\Composer\Autoload\ComposerStaticInit65e5f51a63291647ab68debc39683336::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
@@ -53,19 +53,19 @@ class ComposerAutoloaderInit65e5f51a63291647ab68debc39683336
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
- $includeFiles = Composer\Autoload\ComposerStaticInit65e5f51a63291647ab68debc39683336::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
- composerRequire65e5f51a63291647ab68debc39683336($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
- function composerRequire65e5f51a63291647ab68debc39683336($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInitf74286d2f9f463ba8f91c37ca7d71d21
6
  {
7
  private static $loader;
8
 
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
+ spl_autoload_register(array('ComposerAutoloaderInitf74286d2f9f463ba8f91c37ca7d71d21', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
+ spl_autoload_unregister(array('ComposerAutoloaderInitf74286d2f9f463ba8f91c37ca7d71d21', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
+ call_user_func(\Composer\Autoload\ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
+ $includeFiles = Composer\Autoload\ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
+ composerRequiref74286d2f9f463ba8f91c37ca7d71d21($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
+ function composerRequiref74286d2f9f463ba8f91c37ca7d71d21($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit65e5f51a63291647ab68debc39683336
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
@@ -66,10 +66,10 @@ class ComposerStaticInit65e5f51a63291647ab68debc39683336
66
  public static function getInitializer(ClassLoader $loader)
67
  {
68
  return \Closure::bind(function () use ($loader) {
69
- $loader->prefixLengthsPsr4 = ComposerStaticInit65e5f51a63291647ab68debc39683336::$prefixLengthsPsr4;
70
- $loader->prefixDirsPsr4 = ComposerStaticInit65e5f51a63291647ab68debc39683336::$prefixDirsPsr4;
71
- $loader->prefixesPsr0 = ComposerStaticInit65e5f51a63291647ab68debc39683336::$prefixesPsr0;
72
- $loader->classMap = ComposerStaticInit65e5f51a63291647ab68debc39683336::$classMap;
73
 
74
  }, null, ClassLoader::class);
75
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
66
  public static function getInitializer(ClassLoader $loader)
67
  {
68
  return \Closure::bind(function () use ($loader) {
69
+ $loader->prefixLengthsPsr4 = ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21::$prefixLengthsPsr4;
70
+ $loader->prefixDirsPsr4 = ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21::$prefixDirsPsr4;
71
+ $loader->prefixesPsr0 = ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21::$prefixesPsr0;
72
+ $loader->classMap = ComposerStaticInitf74286d2f9f463ba8f91c37ca7d71d21::$classMap;
73
 
74
  }, null, ClassLoader::class);
75
  }
vendor/composer/installed.json CHANGED
@@ -190,17 +190,17 @@
190
  },
191
  {
192
  "name": "weglot/weglot-php",
193
- "version": "1.1.13",
194
- "version_normalized": "1.1.13.0",
195
  "source": {
196
  "type": "git",
197
  "url": "git@github.com:weglot/weglot-php.git",
198
- "reference": "022336df150ebb01cecc80b035ec3556521f1c24"
199
  },
200
  "dist": {
201
  "type": "zip",
202
- "url": "https://api.github.com/repos/weglot/weglot-php/zipball/022336df150ebb01cecc80b035ec3556521f1c24",
203
- "reference": "022336df150ebb01cecc80b035ec3556521f1c24",
204
  "shasum": ""
205
  },
206
  "require": {
@@ -213,7 +213,7 @@
213
  "codeception/codeception": "^2.4",
214
  "vlucas/phpdotenv": "^2.4"
215
  },
216
- "time": "2021-09-03T15:18:13+00:00",
217
  "type": "library",
218
  "installation-source": "dist",
219
  "autoload": {
190
  },
191
  {
192
  "name": "weglot/weglot-php",
193
+ "version": "1.3",
194
+ "version_normalized": "1.3.0.0",
195
  "source": {
196
  "type": "git",
197
  "url": "git@github.com:weglot/weglot-php.git",
198
+ "reference": "e2b5413fbf38380167867f085bc24a1796c94fd5"
199
  },
200
  "dist": {
201
  "type": "zip",
202
+ "url": "https://api.github.com/repos/weglot/weglot-php/zipball/e2b5413fbf38380167867f085bc24a1796c94fd5",
203
+ "reference": "e2b5413fbf38380167867f085bc24a1796c94fd5",
204
  "shasum": ""
205
  },
206
  "require": {
213
  "codeception/codeception": "^2.4",
214
  "vlucas/phpdotenv": "^2.4"
215
  },
216
+ "time": "2021-11-23T13:32:43+00:00",
217
  "type": "library",
218
  "installation-source": "dist",
219
  "autoload": {
vendor/composer/installed.php CHANGED
@@ -6,7 +6,7 @@
6
  'aliases' =>
7
  array (
8
  ),
9
- 'reference' => 'b3ace5ac887a72333f797353f3c57aaeab2c2692',
10
  'name' => 'weglot/translate-wordpress',
11
  ),
12
  'versions' =>
@@ -45,7 +45,7 @@
45
  'aliases' =>
46
  array (
47
  ),
48
- 'reference' => 'b3ace5ac887a72333f797353f3c57aaeab2c2692',
49
  ),
50
  'weglot/translation-definitions' =>
51
  array (
@@ -58,12 +58,12 @@
58
  ),
59
  'weglot/weglot-php' =>
60
  array (
61
- 'pretty_version' => '1.1.13',
62
- 'version' => '1.1.13.0',
63
  'aliases' =>
64
  array (
65
  ),
66
- 'reference' => '022336df150ebb01cecc80b035ec3556521f1c24',
67
  ),
68
  ),
69
  );
6
  'aliases' =>
7
  array (
8
  ),
9
+ 'reference' => '8a0ce8d7cbb4a77b2d322bc47f4e2b8a3b274e3d',
10
  'name' => 'weglot/translate-wordpress',
11
  ),
12
  'versions' =>
45
  'aliases' =>
46
  array (
47
  ),
48
+ 'reference' => '8a0ce8d7cbb4a77b2d322bc47f4e2b8a3b274e3d',
49
  ),
50
  'weglot/translation-definitions' =>
51
  array (
58
  ),
59
  'weglot/weglot-php' =>
60
  array (
61
+ 'pretty_version' => '1.3',
62
+ 'version' => '1.3.0.0',
63
  'aliases' =>
64
  array (
65
  ),
66
+ 'reference' => 'e2b5413fbf38380167867f085bc24a1796c94fd5',
67
  ),
68
  ),
69
  );
vendor/weglot/weglot-php/.codeclimate.yml DELETED
@@ -1,5 +0,0 @@
1
- version: "2"
2
- checks:
3
- method-complexity:
4
- config:
5
- threshold: 10
 
 
 
 
 
vendor/weglot/weglot-php/.editorconfig DELETED
@@ -1,8 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- indent_size = 4
6
- indent_style = space
7
- insert_final_newline = true
8
- trim_trailing_whitespace = true
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/.env.dist DELETED
@@ -1,9 +0,0 @@
1
- ###> redis ###
2
- REDIS_SCHEME=tcp
3
- REDIS_HOST=127.0.0.1
4
- REDIS_PORT=6379
5
- ###< redis ###
6
-
7
- ###> weglot ###
8
- WG_API_KEY=%%YOUR_WEGLOT_API_KEY%%
9
- ###< redis ###
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/.github/ISSUE_TEMPLATE.md DELETED
@@ -1,15 +0,0 @@
1
- <!-- This form is for bug reports and feature requests ONLY! -->
2
-
3
- **Is this a BUG REPORT or FEATURE REQUEST?**:
4
-
5
- **What happened**:
6
-
7
- **What you expected to happen**:
8
-
9
- **How to reproduce it (some code is appreciated)**:
10
-
11
- **Anything else we need to know?**:
12
-
13
- **Environment**:
14
- - Library version
15
- - PHP version
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/.github/PULL_REQUEST_TEMPLATE.md DELETED
@@ -1,11 +0,0 @@
1
- <!-- Thanks for sending a pull request! If this is your first time, read our contributor guidelines -->
2
-
3
- **What this PR does / why we need it**:
4
-
5
- **Which issue(s) this PR fixes**:
6
- <!-- We suggest to use issue number with tag: #XX -->
7
- - Fixes #
8
-
9
- **Special notes for your reviewer**:
10
-
11
- **How you would summarize your PR ? (for changelog)**:
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/.github/workflows/php.yml DELETED
@@ -1,72 +0,0 @@
1
- name: PHP Composer
2
-
3
- on:
4
- push:
5
- branches: [ develop,master ]
6
- pull_request:
7
- branches: [ develop,master ]
8
-
9
- jobs:
10
- run:
11
- runs-on: ${{ matrix.operating-system }}
12
- strategy:
13
- matrix:
14
- operating-system: [ 'ubuntu-18.04' ]
15
- php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.4' ]
16
- phpunit-versions: [ 'latest' ]
17
- #include:
18
- #- operating-system: 'ubuntu-latest'
19
- # php-versions: '7.2'
20
- # phpunit-versions: '8.5.13'
21
- steps:
22
- - name: Checkout
23
- uses: actions/checkout@v2
24
-
25
- - name: Make envfile
26
- uses: SpicyPizza/create-envfile@v1
27
- with:
28
- envkey_DEBUG: false
29
- envkey_WG_API_KEY: ${{ secrets.WG_API_KEY }}
30
- envkey_REDIS_SCHEME: tcp
31
- envkey_REDIS_HOST: 127.0.0.1
32
- envkey_REDIS_PORT: 6379
33
- file_name: .env
34
- - name: Setup PHP
35
- uses: shivammathur/setup-php@v2
36
- with:
37
- php-version: ${{ matrix.php-versions }}
38
- extensions: mbstring, intl
39
- ini-values: post_max_size=256M, max_execution_time=180
40
- coverage: xdebug
41
- tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
42
-
43
- - name: Redis Server in GitHub Actions
44
- uses: supercharge/redis-github-action@1.1.0
45
-
46
- - name: Cache Composer packages
47
- id: composer-cache
48
- uses: actions/cache@v2
49
- with:
50
- path: vendor
51
- key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
52
- restore-keys: |
53
- ${{ runner.os }}-php-
54
-
55
- - name: Install dependencies
56
- run: composer update --no-progress --no-suggest --ansi --prefer-dist && composer require cache/predis-adapter
57
-
58
- #- name: before test
59
- # run: cp .env.dist .env && sed -i "8s/.*/WG_API_KEY=$WG_API_KEY/" .env
60
-
61
- - name: Validate composer.json and composer.lock
62
- run: composer validate --strict
63
-
64
- - name: launch test
65
- run: ./vendor/bin/codecept run unit --no-interaction
66
-
67
-
68
- # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
69
- # Docs: https://getcomposer.org/doc/articles/scripts.md
70
-
71
- # - name: Run test suite
72
- # run: composer run-script test
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/.travis.yml DELETED
@@ -1,62 +0,0 @@
1
- language: php
2
-
3
- services:
4
- - redis-server
5
-
6
- dist: trusty
7
-
8
- notifications:
9
- email:
10
- on_failure: change
11
-
12
- env:
13
- global:
14
- - COMPOSER_UP="composer update --no-progress --no-suggest --ansi --prefer-dist"
15
- - TEST_COMMAND="./vendor/bin/codecept run unit --no-interaction"
16
- - TEST_FLAGS=""
17
- - DEPENDENCIES="cache/predis-adapter"
18
-
19
- matrix:
20
- fast_finish: true
21
- include:
22
- - php: 5.6
23
- - php: 7.0
24
- - php: 7.1
25
- - php: 7.2
26
- # - php: 7.3
27
- # env: COVERAGE=true TEST_FLAGS="--coverage --coverage-xml"
28
-
29
- install:
30
- - composer config -g github-oauth.github.com "$TOKEN"
31
- - |
32
- if [[ $prefer = low ]]; then
33
- $COMPOSER_UP --prefer-lowest --prefer-stable
34
- else
35
- $COMPOSER_UP
36
- fi
37
- - if ! [ -z "$DEPENDENCIES" ]; then composer require ${DEPENDENCIES}; fi;
38
-
39
- before_script:
40
- - cp .env.dist .env
41
- - sed -i "8s/.*/WG_API_KEY=$WG_API_KEY/" .env
42
- - |
43
- if [[ $COVERAGE = true ]]; then
44
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
45
- chmod +x ./cc-test-reporter
46
- ./cc-test-reporter before-build
47
- fi
48
-
49
- script:
50
- - composer validate --strict --no-check-lock
51
- - $TEST_COMMAND $TEST_FLAGS
52
-
53
- after_script:
54
- - |
55
- if [[ $COVERAGE = true ]]; then
56
- mv tests/_output/coverage.xml clover.xml
57
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
58
- fi
59
-
60
- cache:
61
- directories:
62
- - $HOME/.composer/cache
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/README.md DELETED
@@ -1,15 +0,0 @@
1
- # Examples
2
-
3
- ## Description
4
-
5
- Here are some use cases for Weglot API
6
-
7
- Each example is independant and can be used out of this repository.
8
- We use `.env` to get Weglot API Key or other credentials and `composer` for dependencies.
9
-
10
- ## List
11
- - [simple-client-translate](./simple-client-translate/) : Quick translation from english to german for 2 sentences
12
- - [cached-client-translate](./cached-client-translate/) : Same as `simple-client-translate` but with some cache
13
- - [parsing-web-page](./parsing-web-page/) : Parsing URL content and translating with Weglot API
14
- - [simple-client-languages](./simple-client-languages/) : Simple language details
15
- - [simple-client-status](./simple-client-status/) : API check-alive
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/cached-client-translate/.env.dist DELETED
@@ -1,9 +0,0 @@
1
- ###> redis ###
2
- REDIS_SCHEME=tcp
3
- REDIS_HOST=127.0.0.1
4
- REDIS_PORT=6379
5
- ###< redis ###
6
-
7
- ###> weglot ###
8
- WG_API_KEY=%%YOUR_WEGLOT_API_KEY%%
9
- ###< redis ###
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/cached-client-translate/composer.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "require": {
3
- "cache/predis-adapter": "^1.0",
4
- "weglot/weglot-php": "^0.2",
5
- "vlucas/phpdotenv": "^2.4"
6
- }
7
- }
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/cached-client-translate/run.php DELETED
@@ -1,78 +0,0 @@
1
- <?php
2
-
3
- require_once __DIR__. '/vendor/autoload.php';
4
-
5
- use Weglot\Client\Client;
6
- use Weglot\Client\Endpoint\Translate;
7
- use GuzzleHttp\Exception\GuzzleException;
8
- use Weglot\Client\Api\Exception\MissingRequiredParamException;
9
- use Weglot\Client\Api\Exception\InvalidWordTypeException;
10
- use Weglot\Client\Api\Exception\MissingWordsOutputException;
11
- use Weglot\Client\Api\Exception\InputAndOutputCountMatchException;
12
- use Weglot\Client\Api\TranslateEntry;
13
- use Weglot\Client\Api\Enum\BotType;
14
- use Weglot\Client\Api\WordEntry;
15
- use Weglot\Client\Api\Enum\WordType;
16
- use Predis\Client as Redis;
17
- use Cache\Adapter\Predis\PredisCachePool;
18
-
19
- // DotEnv
20
- $dotenv = new \Dotenv\Dotenv(__DIR__);
21
- $dotenv->load();
22
-
23
- // Caching
24
- $redis = new Redis([
25
- 'scheme' => getenv('REDIS_SCHEME'),
26
- 'host' => getenv('REDIS_HOST'),
27
- 'port' => getenv('REDIS_PORT'),
28
- ]);
29
- $redisPool = new PredisCachePool($redis);
30
-
31
- // TranslateEntry
32
- $params = [
33
- 'language_from' => 'en',
34
- 'language_to' => 'de',
35
- 'title' => 'Weglot | Translate your website - Multilingual for WordPress, Shopify, ...',
36
- 'request_url' => 'https://weglot.com/',
37
- 'bot' => BotType::HUMAN
38
- ];
39
- try {
40
- $translate = new TranslateEntry($params);
41
- $translate->getInputWords()
42
- ->addOne(new WordEntry('This is a blue car', WordType::TEXT))
43
- ->addOne(new WordEntry('This is a black car', WordType::TEXT));
44
- } catch (InvalidWordTypeException $e) {
45
- // input params issues, WordType on WordEntry construct needs to be valid
46
- die($e->getMessage());
47
- } catch (MissingRequiredParamException $e) {
48
- // input params issues, just need to have required fields
49
- die($e->getMessage());
50
- }
51
-
52
- // Client
53
- $client = new Client(getenv('WG_API_KEY'));
54
- $client->setCacheItemPool($redisPool);
55
- $translate = new Translate($translate, $client);
56
-
57
- // Run API :)
58
- try {
59
- $object = $translate->handle();
60
- } catch (InvalidWordTypeException $e) {
61
- // input params issues, shouldn't happen on server response
62
- die($e->getMessage());
63
- } catch (MissingRequiredParamException $e) {
64
- // input params issues, shouldn't happen on server response
65
- die($e->getMessage());
66
- } catch (MissingWordsOutputException $e) {
67
- // api return doesn't contains "to_words", shouldn't happen on server response
68
- die($e->getMessage());
69
- } catch (InputAndOutputCountMatchException $e) {
70
- // api return doesn't contains same number of input & output words, shouldn't happen on server response
71
- die($e->getMessage());
72
- } catch (GuzzleException $e) {
73
- // network issues
74
- die($e->getMessage());
75
- }
76
-
77
- // dumping returned object
78
- var_dump($object);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/parsing-web-page/.env.dist DELETED
@@ -1,3 +0,0 @@
1
- ###> weglot ###
2
- WG_API_KEY=%%YOUR_WEGLOT_API_KEY%%
3
- ###< redis ###
 
 
 
vendor/weglot/weglot-php/examples/parsing-web-page/composer.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "require": {
3
- "weglot/weglot-php": "^0.2",
4
- "vlucas/phpdotenv": "^2.4"
5
- }
6
- }
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/parsing-web-page/run.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
-
3
- require_once __DIR__. '/vendor/autoload.php';
4
-
5
- use Weglot\Client\Client;
6
- use Weglot\Parser\Parser;
7
- use Weglot\Parser\ConfigProvider\ServerConfigProvider;
8
- use Weglot\Parser\ConfigProvider\ManualConfigProvider;
9
- use Weglot\Client\Api\Enum\BotType;
10
- use Weglot\Util\Site;
11
-
12
- // DotEnv
13
- $dotenv = new \Dotenv\Dotenv(__DIR__);
14
- $dotenv->load();
15
-
16
- // Url to parse
17
- $url = 'https://weglot.com/documentation/getting-started';
18
-
19
- // Config with $_SERVER variables
20
- $_SERVER['SERVER_NAME'] = 'weglot.com';
21
- $_SERVER['REQUEST_URI'] = '/documentation/getting-started';
22
- $_SERVER['HTTPS'] = 'on';
23
- $_SERVER['SERVER_PROTOCOL'] = 'http//';
24
- $_SERVER['SERVER_PORT'] = 443;
25
- $_SERVER['HTTP_USER_AGENT'] = 'Google';
26
- $config = new ServerConfigProvider();
27
-
28
- // Config manually
29
- $config = new ManualConfigProvider($url, BotType::HUMAN);
30
-
31
- // Client
32
- $client = new Client(getenv('WG_API_KEY'));
33
- $parser = new Parser($client, $config);
34
-
35
- // Run the Parser
36
- $translatedContent = $parser->translate(Site::get($url), 'en', 'de');
37
-
38
- // dumping returned object
39
- echo $translatedContent;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/simple-client-languages/.env.dist DELETED
@@ -1,3 +0,0 @@
1
- ###> weglot ###
2
- WG_API_KEY=%%YOUR_WEGLOT_API_KEY%%
3
- ###< redis ###
 
 
 
vendor/weglot/weglot-php/examples/simple-client-languages/composer.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "require": {
3
- "weglot/weglot-php": "^0.2",
4
- "vlucas/phpdotenv": "^2.4"
5
- }
6
- }
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/simple-client-languages/run.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- require_once __DIR__. '/vendor/autoload.php';
4
-
5
- use Weglot\Client\Client;
6
- use Weglot\Client\Endpoint\LanguagesList;
7
- use Weglot\Client\Api\Exception\InvalidLanguageException;
8
-
9
- // DotEnv
10
- $dotenv = new \Dotenv\Dotenv(__DIR__);
11
- $dotenv->load();
12
-
13
- // Client
14
- $client = new Client(getenv('WG_API_KEY'));
15
- $languages = new Languages($client);
16
-
17
- // Run API :)
18
- $object = $languages->handle();
19
-
20
- // dumping returned object
21
- var_dump($object->getCode('fi'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/simple-client-status/.env.dist DELETED
@@ -1,3 +0,0 @@
1
- ###> weglot ###
2
- WG_API_KEY=%%YOUR_WEGLOT_API_KEY%%
3
- ###< redis ###
 
 
 
vendor/weglot/weglot-php/examples/simple-client-status/composer.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "require": {
3
- "weglot/weglot-php": "^0.2",
4
- "vlucas/phpdotenv": "^2.4"
5
- }
6
- }
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/simple-client-status/run.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- require_once __DIR__. '/vendor/autoload.php';
4
-
5
- use Weglot\Client\Client;
6
- use GuzzleHttp\Exception\GuzzleException;
7
- use Weglot\Client\Endpoint\Status;
8
-
9
- // DotEnv
10
- $dotenv = new \Dotenv\Dotenv(__DIR__);
11
- $dotenv->load();
12
-
13
- // Client
14
- $client = new Client(getenv('WG_API_KEY'));
15
- $status = new Status($client);
16
-
17
- // Run API :)
18
- try {
19
- $object = $status->handle();
20
- } catch (GuzzleException $e) {
21
- // network issues
22
- die($e->getMessage());
23
- }
24
-
25
- // dumping returned object
26
- var_dump($object);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/simple-client-translate/.env.dist DELETED
@@ -1,3 +0,0 @@
1
- ###> weglot ###
2
- WG_API_KEY=%%YOUR_WEGLOT_API_KEY%%
3
- ###< redis ###
 
 
 
vendor/weglot/weglot-php/examples/simple-client-translate/composer.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "require": {
3
- "weglot/weglot-php": "^0.2",
4
- "vlucas/phpdotenv": "^2.4"
5
- }
6
- }
 
 
 
 
 
 
vendor/weglot/weglot-php/examples/simple-client-translate/run.php DELETED
@@ -1,67 +0,0 @@
1
- <?php
2
-
3
- require_once __DIR__. '/vendor/autoload.php';
4
-
5
- use Weglot\Client\Client;
6
- use Weglot\Client\Endpoint\Translate;
7
- use GuzzleHttp\Exception\GuzzleException;
8
- use Weglot\Client\Api\Exception\MissingRequiredParamException;
9
- use Weglot\Client\Api\Exception\InvalidWordTypeException;
10
- use Weglot\Client\Api\Exception\MissingWordsOutputException;
11
- use Weglot\Client\Api\Exception\InputAndOutputCountMatchException;
12
- use Weglot\Client\Api\TranslateEntry;
13
- use Weglot\Client\Api\Enum\BotType;
14
- use Weglot\Client\Api\WordEntry;
15
- use Weglot\Client\Api\Enum\WordType;
16
-
17
- // DotEnv
18
- $dotenv = new \Dotenv\Dotenv(__DIR__);
19
- $dotenv->load();
20
-
21
- // TranslateEntry
22
- $params = [
23
- 'language_from' => 'en',
24
- 'language_to' => 'de',
25
- 'title' => 'Weglot | Translate your website - Multilingual for WordPress, Shopify, ...',
26
- 'request_url' => 'https://weglot.com/',
27
- 'bot' => BotType::HUMAN
28
- ];
29
- try {
30
- $translate = new TranslateEntry($params);
31
- $translate->getInputWords()
32
- ->addOne(new WordEntry('This is a blue car', WordType::TEXT))
33
- ->addOne(new WordEntry('This is a black car', WordType::TEXT));
34
- } catch (InvalidWordTypeException $e) {
35
- // input params issues, WordType on WordEntry construct needs to be valid
36
- die($e->getMessage());
37
- } catch (MissingRequiredParamException $e) {
38
- // input params issues, just need to have required fields
39
- die($e->getMessage());
40
- }
41
-
42
- // Client
43
- $client = new Client(getenv('WG_API_KEY'));
44
- $translate = new Translate($translate, $client);
45
-
46
- // Run API :)
47
- try {
48
- $object = $translate->handle();
49
- } catch (InvalidWordTypeException $e) {
50
- // input params issues, shouldn't happen on server response
51
- die($e->getMessage());
52
- } catch (MissingRequiredParamException $e) {
53
- // input params issues, shouldn't happen on server response
54
- die($e->getMessage());
55
- } catch (MissingWordsOutputException $e) {
56
- // api return doesn't contains "to_words", shouldn't happen on server response
57
- die($e->getMessage());
58
- } catch (InputAndOutputCountMatchException $e) {
59
- // api return doesn't contains same number of input & output words, shouldn't happen on server response
60
- die($e->getMessage());
61
- } catch (GuzzleException $e) {
62
- // network issues
63
- die($e->getMessage());
64
- }
65
-
66
- // dumping returned object
67
- var_dump($object);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/src/Client/Client.php CHANGED
@@ -31,6 +31,13 @@ class Client
31
  */
32
  protected $apiKey;
33
 
 
 
 
 
 
 
 
34
  /**
35
  * Options for client
36
  *
@@ -58,12 +65,14 @@ class Client
58
  /**
59
  * Client constructor.
60
  * @param string $apiKey your Weglot API key
 
61
  * @param int $translationEngine
62
  * @param array $options an array of options, currently only "host" is implemented
63
  */
64
- public function __construct($apiKey, $translationEngine, $options = [])
65
  {
66
  $this->apiKey = $apiKey;
 
67
  $this->profile = new Profile($apiKey, $translationEngine);
68
 
69
  $this
@@ -197,11 +206,11 @@ class Client
197
  {
198
  try {
199
  if($method === 'GET') {
200
- $urlParams = array_merge( ['api_key' => $this->apiKey , ], $body);
201
  $body = [];
202
  }
203
  else {
204
- $urlParams = ['api_key' => $this->apiKey];
205
  }
206
  list($rawBody, $httpStatusCode, $httpHeader) = $this->getHttpClient()->request(
207
  $method,
31
  */
32
  protected $apiKey;
33
 
34
+ /**
35
+ * Weglot settings file Version
36
+ *
37
+ * @var string
38
+ */
39
+ protected $version;
40
+
41
  /**
42
  * Options for client
43
  *
65
  /**
66
  * Client constructor.
67
  * @param string $apiKey your Weglot API key
68
+ * @param string $version your settings file version
69
  * @param int $translationEngine
70
  * @param array $options an array of options, currently only "host" is implemented
71
  */
72
+ public function __construct($apiKey, $version = '1', $translationEngine, $options = [])
73
  {
74
  $this->apiKey = $apiKey;
75
+ $this->version = $version;
76
  $this->profile = new Profile($apiKey, $translationEngine);
77
 
78
  $this
206
  {
207
  try {
208
  if($method === 'GET') {
209
+ $urlParams = array_merge( ['api_key' => $this->apiKey, 'v' => $this->version], $body);
210
  $body = [];
211
  }
212
  else {
213
+ $urlParams = ['api_key' => $this->apiKey, 'v' => $this->version];
214
  }
215
  list($rawBody, $httpStatusCode, $httpHeader) = $this->getHttpClient()->request(
216
  $method,
vendor/weglot/weglot-php/src/Client/Endpoint/CdnTranslate.php CHANGED
@@ -17,7 +17,7 @@ use Weglot\Client\Factory\Translate as TranslateFactory;
17
  */
18
  class CdnTranslate extends Endpoint
19
  {
20
- const METHOD = 'GET';
21
  const ENDPOINT = '/translate';
22
 
23
  /**
@@ -35,7 +35,7 @@ class CdnTranslate extends Endpoint
35
  $this->setTranslateEntry($translateEntry);
36
  $currentHost = $client->getOptions()['host'];
37
  if($currentHost) {
38
- $cdnHost = str_replace('https://api.weglot.' , 'https://cdn-api.weglot.' , $currentHost);
39
  $client->setOptions(array('host' => $cdnHost ));
40
  }
41
  parent::__construct($client);
@@ -70,27 +70,17 @@ class CdnTranslate extends Endpoint
70
  */
71
  public function handle()
72
  {
73
- $beforeRequest = [];
74
  $asArray = $this->translateEntry->jsonSerialize();
75
-
76
- $w = $t = "[";
77
- foreach ($asArray['words'] as $word) {
78
- $w .= json_encode($word['w']) . ",";
79
- $t .= json_encode($word['t']) . ",";
80
- }
81
- $asArray['w'] = trim($w,",") . "]";
82
- $asArray['t'] = trim($t, ",") . "]";
83
- unset($asArray['words']);
84
-
85
- $asArray['v'] = 0; // REPLACE with version when it's released.
86
-
87
- if (!empty($asArray['w'])) {
88
  list($rawBody, $httpStatusCode) = $this->request($asArray, false);
89
  if ($httpStatusCode !== 200) {
90
  throw new ApiError($rawBody, $asArray);
91
  }
92
  $response = json_decode($rawBody, true);
93
  }
 
 
 
94
 
95
  $factory = new TranslateFactory($response);
96
  return $factory->handle();
17
  */
18
  class CdnTranslate extends Endpoint
19
  {
20
+ const METHOD = 'POST';
21
  const ENDPOINT = '/translate';
22
 
23
  /**
35
  $this->setTranslateEntry($translateEntry);
36
  $currentHost = $client->getOptions()['host'];
37
  if($currentHost) {
38
+ $cdnHost = str_replace('https://api.weglot.' , 'https://cdn-api-weglot.' , $currentHost);
39
  $client->setOptions(array('host' => $cdnHost ));
40
  }
41
  parent::__construct($client);
70
  */
71
  public function handle()
72
  {
 
73
  $asArray = $this->translateEntry->jsonSerialize();
74
+ if (!empty($asArray['words'])) {
 
 
 
 
 
 
 
 
 
 
 
 
75
  list($rawBody, $httpStatusCode) = $this->request($asArray, false);
76
  if ($httpStatusCode !== 200) {
77
  throw new ApiError($rawBody, $asArray);
78
  }
79
  $response = json_decode($rawBody, true);
80
  }
81
+ else {
82
+ throw new ApiError("Empty words passed", $asArray);
83
+ }
84
 
85
  $factory = new TranslateFactory($response);
86
  return $factory->handle();
vendor/weglot/weglot-php/src/Client/Endpoint/LanguagesList.php CHANGED
@@ -47,8 +47,10 @@ class LanguagesList extends Endpoint
47
  }, $data);
48
 
49
  foreach ($data as $language) {
50
- $factory = new LanguagesFactory($language);
51
- $languageCollection->addOne($factory->handle());
 
 
52
  }
53
 
54
  return $languageCollection;
47
  }, $data);
48
 
49
  foreach ($data as $language) {
50
+ if($language['internal_code'] != 'fc'){
51
+ $factory = new LanguagesFactory($language);
52
+ $languageCollection->addOne($factory->handle());
53
+ }
54
  }
55
 
56
  return $languageCollection;
vendor/weglot/weglot-php/src/Parser/Formatter/CustomSwitchersFormatter.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Weglot\Parser\Formatter;
4
+
5
+ use WGSimpleHtmlDom\simple_html_dom;
6
+ use Weglot\Parser\Parser;
7
+
8
+ class CustomSwitchersFormatter
9
+ {
10
+ /**
11
+ * @var simple_html_dom
12
+ */
13
+ protected $dom;
14
+
15
+ /**
16
+ * @var array
17
+ */
18
+ protected $customSwitchers;
19
+
20
+ /**
21
+ * CustomSwitchersFormatter constructor.
22
+ * @param $dom
23
+ */
24
+ public function __construct($dom, $customSwitchers)
25
+ {
26
+ $this
27
+ ->setDom($dom)
28
+ ->setCustomSwitchers($customSwitchers);
29
+ $this->handle($this->dom, $customSwitchers);
30
+ }
31
+
32
+ /**
33
+ * @param simple_html_dom $dom
34
+ * @return $this
35
+ */
36
+ public function setDom(simple_html_dom $dom)
37
+ {
38
+ $this->dom = $dom;
39
+
40
+ return $this;
41
+ }
42
+
43
+ /**
44
+ * @return simple_html_dom
45
+ */
46
+ public function getDom()
47
+ {
48
+ return $this->dom;
49
+ }
50
+
51
+ /**
52
+ * @param array $customSwitchers
53
+ * @return $this
54
+ */
55
+ public function setCustomSwitchers(array $customSwitchers)
56
+ {
57
+ $this->customSwitchers = $customSwitchers;
58
+
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * @return array
64
+ */
65
+ public function getCustomSwitchers()
66
+ {
67
+ return $this->customSwitchers;
68
+ }
69
+
70
+ /**
71
+ * <div class="target">target</div> foreach customswitchers
72
+ * wanna be translated.
73
+ *
74
+ * @return simple_html_dom
75
+ */
76
+ public function handle($dom, $switchers)
77
+ {
78
+ foreach ($switchers as $switcher) {
79
+
80
+ $location = $switcher['location'];
81
+ if ( ! empty( $location ) ) {
82
+ if ( $dom->find( $location['target'] ) && is_array( $dom->find( $location['target'] ) ) ) {
83
+ foreach ( $dom->find( $location['target'] ) as $target ) {
84
+ if ( empty( $location['sibling'] ) ) {
85
+ $target->innertext .= '<div data-wg-position="'.$location['target'].'"></div>';
86
+ } else {
87
+ if ( $target->find( $location['sibling'] ) ) {
88
+ foreach ( $target->find( $location['sibling'], 0 ) as $sibling ) {
89
+ if ( is_object( $sibling ) ) {
90
+ $sibling->innertext = '<div data-wg-position="'.$location['target'].' '.$location['sibling'].'"></div>' . $sibling->innertext;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ }
99
+ return $dom;
100
+ }
101
+ }
vendor/weglot/weglot-php/src/Parser/Parser.php CHANGED
@@ -8,6 +8,7 @@ use Weglot\Client\Api\WordEntry;
8
  use Weglot\Client\Endpoint\CdnTranslate;
9
  use Weglot\Parser\Check\Regex\JsonChecker;
10
  use Weglot\Parser\Check\RegexCheckerProvider;
 
11
  use Weglot\Parser\Formatter\JsonFormatter;
12
  use Weglot\Util\SourceType;
13
  use Weglot\Util\Text;
@@ -56,6 +57,11 @@ class Parser {
56
  */
57
  protected $excludeBlocks;
58
 
 
 
 
 
 
59
  /**
60
  * @var string
61
  */
@@ -92,12 +98,14 @@ class Parser {
92
  * @param Client $client
93
  * @param ConfigProviderInterface $config
94
  * @param array $excludeBlocks
 
95
  */
96
- public function __construct( Client $client, ConfigProviderInterface $config, array $excludeBlocks = [] ) {
97
  $this
98
  ->setClient( $client )
99
  ->setConfigProvider( $config )
100
  ->setExcludeBlocks( $excludeBlocks )
 
101
  ->setWords( new WordCollection() )
102
  ->setDomCheckerProvider( new DomCheckerProvider( $this, $client->getProfile()->getTranslationEngine() ) )
103
  ->setRegexCheckerProvider( new RegexCheckerProvider( $this ) )
@@ -140,6 +148,24 @@ class Parser {
140
  return $this->excludeBlocks;
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  /**
144
  * @param ConfigProviderInterface $config
145
  *
@@ -358,6 +384,12 @@ class Parser {
358
  $dom = $excludeBlocks->getDom();
359
  }
360
 
 
 
 
 
 
 
361
  // checkers
362
  list( $nodes, $regexes ) = $this->checkers( $dom, $source );
363
 
@@ -416,12 +448,7 @@ class Parser {
416
  die( $e->getMessage() );
417
  }
418
 
419
- if (strpos($this->getConfigProvider()->getUrl(), '/404') !== false) {
420
- $translate = new CdnTranslate($translate, $this->client); //TODO: use CDNTranslate once working better.
421
- }
422
- else {
423
- $translate = new Translate($translate, $this->client);
424
- }
425
  return $translate->handle();
426
  }
427
 
8
  use Weglot\Client\Endpoint\CdnTranslate;
9
  use Weglot\Parser\Check\Regex\JsonChecker;
10
  use Weglot\Parser\Check\RegexCheckerProvider;
11
+ use Weglot\Parser\Formatter\CustomSwitchersFormatter;
12
  use Weglot\Parser\Formatter\JsonFormatter;
13
  use Weglot\Util\SourceType;
14
  use Weglot\Util\Text;
57
  */
58
  protected $excludeBlocks;
59
 
60
+ /**
61
+ * @var array
62
+ */
63
+ protected $customSwitchers;
64
+
65
  /**
66
  * @var string
67
  */
98
  * @param Client $client
99
  * @param ConfigProviderInterface $config
100
  * @param array $excludeBlocks
101
+ * @param array $customSwitchers
102
  */
103
+ public function __construct( Client $client, ConfigProviderInterface $config, array $excludeBlocks = [], array $customSwitchers = [] ) {
104
  $this
105
  ->setClient( $client )
106
  ->setConfigProvider( $config )
107
  ->setExcludeBlocks( $excludeBlocks )
108
+ ->setCustomSwitchers( $customSwitchers )
109
  ->setWords( new WordCollection() )
110
  ->setDomCheckerProvider( new DomCheckerProvider( $this, $client->getProfile()->getTranslationEngine() ) )
111
  ->setRegexCheckerProvider( new RegexCheckerProvider( $this ) )
148
  return $this->excludeBlocks;
149
  }
150
 
151
+ /**
152
+ * @param array $customSwitchers
153
+ *
154
+ * @return $this
155
+ */
156
+ public function setCustomSwitchers( array $customSwitchers ) {
157
+ $this->customSwitchers = $customSwitchers;
158
+
159
+ return $this;
160
+ }
161
+
162
+ /**
163
+ * @return array
164
+ */
165
+ public function getCustomSwitchers() {
166
+ return $this->customSwitchers;
167
+ }
168
+
169
  /**
170
  * @param ConfigProviderInterface $config
171
  *
384
  $dom = $excludeBlocks->getDom();
385
  }
386
 
387
+ // custom switchers
388
+ if ( ! empty( $this->customSwitchers ) ) {
389
+ $customSwitchers = new CustomSwitchersFormatter( $dom, $this->customSwitchers );
390
+ $dom = $customSwitchers->getDom();
391
+ }
392
+
393
  // checkers
394
  list( $nodes, $regexes ) = $this->checkers( $dom, $source );
395
 
448
  die( $e->getMessage() );
449
  }
450
 
451
+ $translate = new CdnTranslate($translate, $this->client);
 
 
 
 
 
452
  return $translate->handle();
453
  }
454
 
vendor/weglot/weglot-php/src/Util/Url.php CHANGED
@@ -185,13 +185,17 @@ class Url
185
 
186
  /**
187
  * @param LanguageEntry $language
 
188
  * @return bool|string
189
  */
190
- public function getForLanguage($language)
191
  {
192
  $urls = $this->getAllUrls();
193
- foreach ($urls as $url) {
194
- if($url['language'] === $language) {
 
 
 
195
  return $url['url'];
196
  }
197
  }
@@ -202,11 +206,12 @@ class Url
202
  * Check if we need to translate given URL
203
  *
204
  * @param LanguageEntry $language
 
205
  * @return bool
206
  */
207
- public function isTranslableInLanguage( $language )
208
  {
209
- if($this->getForLanguage($language)) {
210
  return true;
211
  }
212
  return false;
@@ -215,14 +220,14 @@ class Url
215
  /**
216
  * Check if we need to translate given URL
217
  *
218
- * @param LanguageEntry $language
219
  * @return bool
220
  */
221
- public function availableInLanguages()
222
  {
223
  $availableLanguage = [];
224
  foreach ($this->destinationLanguages as $destinationLanguage) {
225
- if($this->getForLanguage($destinationLanguage)) {
226
  $availableLanguage[] = $destinationLanguage;
227
  }
228
  }
@@ -348,19 +353,27 @@ class Url
348
  $originalURL .= '#'. $this->getFragment();
349
  }
350
 
351
- $urls[] = array( 'language' => $this->originalLanguage, 'url' => $originalURL);
352
- foreach ($this->destinationLanguages as $language) {
353
 
 
 
354
  foreach ($this->excludedUrls as $excludedUrl) {
 
355
  if( $excludedUrl[1] === null || ( is_array($excludedUrl[1]) && in_array($language, $excludedUrl[1]) ) ) {
 
356
  if (strpos($excludedUrl[0], '?!') !== false) { // Si la regex contient un negative lookahead, alors on check le match entre le path et la regex
357
- if( preg_match('#' . $excludedUrl[0] . '#', $this->getPath()) != 0)
358
- continue 2;
 
 
359
  }
360
  else { //Sinon on check le match entre le path et le rtrim(path)
361
  if( preg_match('#' . $excludedUrl[0] . '#', $this->getPath()) != 0
362
- || preg_match('#' . $excludedUrl[0] . '#', rtrim($this->getPath() , "/")) != 0 )
363
- continue 2;
 
 
 
364
  }
365
  }
366
  }
@@ -387,7 +400,7 @@ class Url
387
  if (!is_null($this->getFragment())) {
388
  $url .= '#'. $this->getFragment();
389
  }
390
- $urls[] = array( 'language' => $language, 'url' => $url);
391
  }
392
 
393
  $this->allUrls = $urls;
185
 
186
  /**
187
  * @param LanguageEntry $language
188
+ * @param bool $getExclusion
189
  * @return bool|string
190
  */
191
+ public function getForLanguage($language, $evenExcluded = false)
192
  {
193
  $urls = $this->getAllUrls();
194
+ foreach ( $urls as $url ) {
195
+ if ( $url['language'] === $language ) {
196
+ if(!$evenExcluded && $url['excluded']){
197
+ return false;
198
+ }
199
  return $url['url'];
200
  }
201
  }
206
  * Check if we need to translate given URL
207
  *
208
  * @param LanguageEntry $language
209
+ * @param bool $evenExcluded
210
  * @return bool
211
  */
212
+ public function isTranslableInLanguage( $language, $evenExcluded = false )
213
  {
214
+ if($this->getForLanguage($language, $evenExcluded)) {
215
  return true;
216
  }
217
  return false;
220
  /**
221
  * Check if we need to translate given URL
222
  *
223
+ * @param bool $evenExcluded
224
  * @return bool
225
  */
226
+ public function availableInLanguages($evenExcluded)
227
  {
228
  $availableLanguage = [];
229
  foreach ($this->destinationLanguages as $destinationLanguage) {
230
+ if($this->getForLanguage($destinationLanguage, $evenExcluded)) {
231
  $availableLanguage[] = $destinationLanguage;
232
  }
233
  }
353
  $originalURL .= '#'. $this->getFragment();
354
  }
355
 
356
+ $urls[] = array( 'language' => $this->originalLanguage, 'url' => $originalURL, 'excluded' => false);
 
357
 
358
+ foreach ($this->destinationLanguages as $language) {
359
+ $isExcluded = false;
360
  foreach ($this->excludedUrls as $excludedUrl) {
361
+
362
  if( $excludedUrl[1] === null || ( is_array($excludedUrl[1]) && in_array($language, $excludedUrl[1]) ) ) {
363
+
364
  if (strpos($excludedUrl[0], '?!') !== false) { // Si la regex contient un negative lookahead, alors on check le match entre le path et la regex
365
+ if( preg_match('#' . $excludedUrl[0] . '#', $this->getPath()) != 0) {
366
+ $isExcluded = true;
367
+ break;
368
+ }
369
  }
370
  else { //Sinon on check le match entre le path et le rtrim(path)
371
  if( preg_match('#' . $excludedUrl[0] . '#', $this->getPath()) != 0
372
+ || preg_match('#' . $excludedUrl[0] . '#', rtrim($this->getPath() , "/")) != 0 ) {
373
+ $isExcluded = true;
374
+ break;
375
+ }
376
+
377
  }
378
  }
379
  }
400
  if (!is_null($this->getFragment())) {
401
  $url .= '#'. $this->getFragment();
402
  }
403
+ $urls[] = array( 'language' => $language, 'url' => $url, 'excluded' => $isExcluded );
404
  }
405
 
406
  $this->allUrls = $urls;
vendor/weglot/weglot-php/tests/_support/AcceptanceTester.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
-
4
- /**
5
- * Inherited Methods
6
- * @method void wantToTest($text)
7
- * @method void wantTo($text)
8
- * @method void execute($callable)
9
- * @method void expectTo($prediction)
10
- * @method void expect($prediction)
11
- * @method void amGoingTo($argumentation)
12
- * @method void am($role)
13
- * @method void lookForwardTo($achieveValue)
14
- * @method void comment($description)
15
- * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
16
- *
17
- * @SuppressWarnings(PHPMD)
18
- */
19
- class AcceptanceTester extends \Codeception\Actor
20
- {
21
- use _generated\AcceptanceTesterActions;
22
-
23
- /**
24
- * Define custom actions here
25
- */
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/_support/FunctionalTester.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
-
4
- /**
5
- * Inherited Methods
6
- * @method void wantToTest($text)
7
- * @method void wantTo($text)
8
- * @method void execute($callable)
9
- * @method void expectTo($prediction)
10
- * @method void expect($prediction)
11
- * @method void amGoingTo($argumentation)
12
- * @method void am($role)
13
- * @method void lookForwardTo($achieveValue)
14
- * @method void comment($description)
15
- * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
16
- *
17
- * @SuppressWarnings(PHPMD)
18
- */
19
- class FunctionalTester extends \Codeception\Actor
20
- {
21
- use _generated\FunctionalTesterActions;
22
-
23
- /**
24
- * Define custom actions here
25
- */
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/_support/Helper/Acceptance.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
- namespace Helper;
3
-
4
- // here you can define custom actions
5
- // all public methods declared in helper class will be available in $I
6
-
7
- class Acceptance extends \Codeception\Module
8
- {
9
- }
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/_support/Helper/Functional.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
- namespace Helper;
3
-
4
- // here you can define custom actions
5
- // all public methods declared in helper class will be available in $I
6
-
7
- class Functional extends \Codeception\Module
8
- {
9
- }
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/_support/Helper/Unit.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
- namespace Helper;
3
-
4
- // here you can define custom actions
5
- // all public methods declared in helper class will be available in $I
6
-
7
- class Unit extends \Codeception\Module
8
- {
9
- }
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/_support/UnitTester.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
-
4
- /**
5
- * Inherited Methods
6
- * @method void wantToTest($text)
7
- * @method void wantTo($text)
8
- * @method void execute($callable)
9
- * @method void expectTo($prediction)
10
- * @method void expect($prediction)
11
- * @method void amGoingTo($argumentation)
12
- * @method void am($role)
13
- * @method void lookForwardTo($achieveValue)
14
- * @method void comment($description)
15
- * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
16
- *
17
- * @SuppressWarnings(PHPMD)
18
- */
19
- class UnitTester extends \Codeception\Actor
20
- {
21
- use _generated\UnitTesterActions;
22
-
23
- /**
24
- * Define custom actions here
25
- */
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/acceptance.suite.yml DELETED
@@ -1,12 +0,0 @@
1
- # Codeception Test Suite Configuration
2
- #
3
- # Suite for acceptance tests.
4
- # Perform tests in browser using the WebDriver or PhpBrowser.
5
- # If you need both WebDriver and PHPBrowser tests - create a separate suite.
6
-
7
- actor: AcceptanceTester
8
- modules:
9
- enabled:
10
- - PhpBrowser:
11
- url: http://localhost/myapp
12
- - \Helper\Acceptance
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/functional.suite.yml DELETED
@@ -1,12 +0,0 @@
1
- # Codeception Test Suite Configuration
2
- #
3
- # Suite for functional tests
4
- # Emulate web requests and make application process them
5
- # Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
6
- # Remove this suite if you don't use frameworks
7
-
8
- actor: FunctionalTester
9
- modules:
10
- enabled:
11
- # add a framework module here
12
- - \Helper\Functional
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit.suite.yml DELETED
@@ -1,14 +0,0 @@
1
- # Codeception Test Suite Configuration
2
- #
3
- # Suite for unit or integration tests.
4
-
5
- actor: UnitTester
6
- groups:
7
- client: ['tests/unit/Client/ClientTest.php', 'tests/unit/Client/Endpoint/Languages.php', 'tests/unit/Client/Endpoint/StatusTest.php', 'tests/unit/Client/Endpoint/TranslateTest.php']
8
- client.cache: ['tests/unit/Client/ClientCachingTest.php', 'tests/unit/Client/CachedTranslateTest.php']
9
- parser: ['tests/unit/Parser/ParserTest.php', 'tests/unit/Parser/Check/Dom/MetaContentTest.php']
10
- util: ['tests/unit/Util/UrlTest.php', 'tests/unit/Util/JsonLdTest.php']
11
- modules:
12
- enabled:
13
- - Asserts
14
- - \Helper\Unit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/ClientCachingTest.php DELETED
@@ -1,84 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Client\Client;
4
- use Predis\Client as Redis;
5
- use Cache\Adapter\Predis\PredisCachePool;
6
-
7
- class ClientCachingTest extends \Codeception\Test\Unit
8
- {
9
- /**
10
- * @var \UnitTester
11
- */
12
- protected $tester;
13
-
14
- /**
15
- * @var \Weglot\Client\Client
16
- */
17
- protected $client;
18
-
19
- /**
20
- * @var Redis
21
- */
22
- protected $redis;
23
-
24
- /**
25
- * Init client & redis-server
26
- */
27
- protected function _before()
28
- {
29
- $this->client = new Client(getenv('WG_API_KEY'), 3);
30
-
31
- $this->redis = new Redis([
32
- 'scheme' => getenv('REDIS_SCHEME'),
33
- 'host' => getenv('REDIS_HOST'),
34
- 'port' => getenv('REDIS_PORT'),
35
- ]);
36
- $this->redis->connect();
37
-
38
- $itemPool = new PredisCachePool($this->redis);
39
- $itemPool->clear();
40
- $this->client->setCacheItemPool($itemPool);
41
- }
42
-
43
- // tests
44
- public function testRedisConnection()
45
- {
46
- $this->assertTrue($this->redis->isConnected());
47
- }
48
-
49
- public function testItemPool()
50
- {
51
- $this->assertTrue($this->client->getCache()->getItemPool() instanceof PredisCachePool);
52
- }
53
-
54
- public function testExpire()
55
- {
56
- $this->assertEquals(604800, $this->client->getCache()->getExpire());
57
-
58
- $this->client->getCache()->setExpire(240);
59
- $this->assertEquals(240, $this->client->getCache()->getExpire());
60
- }
61
-
62
- public function testGenerateKey()
63
- {
64
- $cacheKey = $this->client->getCache()->generateKey([
65
- 'method' => 'GET',
66
- 'endpoint' => '/translate',
67
- 'content' => []
68
- ]);
69
- $this->assertEquals('wg_8bdaed005c88bda03e938c3de08da157ecbe5dfa', $cacheKey);
70
- }
71
-
72
- public function testGetItem()
73
- {
74
- $key = 'getItem';
75
- $item = $this->client->getCache()->get($key);
76
-
77
- $this->assertNull($item->get());
78
-
79
- $item->set('some value');
80
- $this->client->getCache()->save($item);
81
-
82
- $this->assertEquals('some value', $this->client->getCache()->get($key)->get());
83
- }
84
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/ClientTest.php DELETED
@@ -1,78 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Client\Client;
4
- use Weglot\Client\HttpClient\CurlClient;
5
-
6
- class ClientTest extends \Codeception\Test\Unit
7
- {
8
- /**
9
- * @var \UnitTester
10
- */
11
- protected $tester;
12
-
13
- /**
14
- * @var \Weglot\Client\Client
15
- */
16
- protected $client;
17
-
18
- /**
19
- * Init client
20
- */
21
- protected function _before()
22
- {
23
- $this->client = new Client(getenv('WG_API_KEY') , 3);
24
- }
25
-
26
- // tests
27
- public function testOptions()
28
- {
29
- $options = $this->client->getOptions();
30
-
31
- $this->assertEquals('https://api.weglot.com', $options['host']);
32
- }
33
-
34
- public function testConnector()
35
- {
36
- $httpClient = $this->client->getHttpClient();
37
-
38
- $this->assertTrue($httpClient instanceof CurlClient);
39
-
40
- $curlVersion = curl_version();
41
- $userAgentInfo = [
42
- 'curl' => 'cURL\\' .$curlVersion['version'],
43
- 'ssl' => $curlVersion['ssl_version']
44
- ];
45
- $this->assertEquals($userAgentInfo, $httpClient->getUserAgentInfo());
46
-
47
- $headers = [
48
- 'Weglot-Context: PHP\\' .Client::VERSION
49
- ];
50
- $this->assertEquals($headers, $httpClient->getDefaultHeaders());
51
- }
52
-
53
- public function testProfile()
54
- {
55
- $wgApiKeys = [
56
- 'wg_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' => 2
57
- ];
58
- foreach ($wgApiKeys as $wgApiKey => $version) {
59
- $client = new Client($wgApiKey , 3);
60
- $profile = $client->getProfile();
61
-
62
- $this->assertEquals($version, $profile->getApiVersion());
63
- $this->assertEquals(3, $profile->getTranslationEngine());
64
- }
65
- }
66
-
67
- public function testMakeRequest()
68
- {
69
- $response = $this->client->makeRequest('GET', '/status', []);
70
- $this->assertEquals([], $response);
71
- }
72
-
73
- public function testMakeRequestAsResponse()
74
- {
75
- list($rawBody, $httpStatusCode, $httpHeader) = $this->client->makeRequest('GET', '/status', [], false);
76
- $this->assertTrue($httpStatusCode === 200);
77
- }
78
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/CachedTranslateTest.php DELETED
@@ -1,122 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Client\Client;
4
- use Weglot\Client\Endpoint\Translate;
5
- use Weglot\Client\Api\TranslateEntry;
6
- use Weglot\Client\Api\Enum\BotType;
7
- use Weglot\Client\Api\WordEntry;
8
- use Weglot\Client\Api\Enum\WordType;
9
- use Weglot\Client\Api\WordCollection;
10
- use Predis\Client as Redis;
11
- use Cache\Adapter\Predis\PredisCachePool;
12
-
13
- class CachedTranslateTest extends \Codeception\Test\Unit
14
- {
15
- /**
16
- * @var \UnitTester
17
- */
18
- protected $tester;
19
-
20
- /**
21
- * @var Client
22
- */
23
- protected $client;
24
-
25
- /**
26
- * @var Redis
27
- */
28
- protected $redis;
29
-
30
- /**
31
- * @var TranslateEntry
32
- */
33
- protected $entry;
34
-
35
- /**
36
- * @var Translate
37
- */
38
- protected $translate;
39
-
40
- /**
41
- * Init client
42
- */
43
- protected function _before()
44
- {
45
- // Client
46
- $this->client = new Client(getenv('WG_API_KEY'), 3);
47
-
48
- // Redis
49
- $this->redis = new Redis([
50
- 'scheme' => getenv('REDIS_SCHEME'),
51
- 'host' => getenv('REDIS_HOST'),
52
- 'port' => getenv('REDIS_PORT'),
53
- ]);
54
- $this->redis->connect();
55
-
56
- // PSR-6 CacheItemPool
57
- $itemPool = new PredisCachePool($this->redis);
58
- $itemPool->clear();
59
- $this->client->setCacheItemPool($itemPool);
60
-
61
- // TranslateEntry
62
- $params = [
63
- 'language_from' => 'en',
64
- 'language_to' => 'de',
65
- 'title' => 'Weglot | Translate your website - Multilingual for WordPress, Shopify, ...',
66
- 'request_url' => 'https://weglot.com/',
67
- 'bot' => BotType::HUMAN
68
- ];
69
-
70
- $this->entry = new TranslateEntry($params);
71
- $this->entry->getInputWords()
72
- ->addOne(new WordEntry('This is a blue car', WordType::TEXT))
73
- ->addOne(new WordEntry('This is a black car', WordType::TEXT));
74
-
75
- // Translate endpoint
76
- $this->translate = new Translate($this->entry, $this->client);
77
- }
78
-
79
- // tests
80
- public function testSetOutputWords()
81
- {
82
- $this->entry->setOutputWords(null);
83
- $this->assertTrue($this->entry->getOutputWords() instanceof WordCollection);
84
- $this->assertEquals(0, $this->entry->getOutputWords()->count());
85
- }
86
-
87
- public function testGetParams()
88
- {
89
- $params = $this->entry->getParams();
90
- $this->assertEquals('en', $params['language_from']);
91
- $this->assertEquals('de', $params['language_to']);
92
- $this->assertEquals('https://weglot.com/', $params['request_url']);
93
- $this->assertEquals(BotType::HUMAN, $params['bot']);
94
- }
95
-
96
- public function testEndpointCountWord()
97
- {
98
- $translated = $this->translate->handle();
99
-
100
- $this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
101
- }
102
-
103
- public function testTranslateEntry()
104
- {
105
- $this->assertTrue($this->translate->getTranslateEntry() instanceof TranslateEntry);
106
- $this->assertTrue($this->translate->getTranslateEntry() === $this->entry);
107
- }
108
-
109
- public function testPath()
110
- {
111
- $this->assertEquals('/translate', $this->translate->getPath());
112
- }
113
-
114
- // public function testCachedRequest()
115
- // {
116
- // $translated = $this->translate->handle();
117
- // $this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
118
-
119
- // $translated = $this->translate->handle();
120
- // $this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
121
- // }
122
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/LanguagesTest.php DELETED
@@ -1,69 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Client\Client;
4
- use Weglot\Client\Endpoint\LanguagesList;
5
- use Weglot\Client\Api\LanguageCollection;
6
-
7
- class LanguagesTest extends \Codeception\Test\Unit
8
- {
9
- /**
10
- * @var \UnitTester
11
- */
12
- protected $tester;
13
-
14
- /**
15
- * @var Client
16
- */
17
- protected $client;
18
-
19
- /**
20
- * @var LanguageCollection
21
- */
22
- protected $languages;
23
-
24
- /**
25
- * Init client
26
- */
27
- protected function _before()
28
- {
29
- $this->client = new Client(getenv('WG_API_KEY'), 3);
30
- $endpoint = new LanguagesList($this->client);
31
- $this->languages = $endpoint->handle();
32
- }
33
-
34
- // tests
35
- public function testCount()
36
- {
37
- $this->assertEquals(117, \count($this->languages));
38
- }
39
-
40
- public function testGetCode()
41
- {
42
- $this->assertEquals('Finnish', $this->languages->getCode('fi')->getEnglishName());
43
- $this->assertEquals('Hrvatski', $this->languages->getCode('hr')->getLocalName());
44
- $this->assertNull($this->languages->getCode('foo'));
45
- }
46
-
47
- public function testSerialize()
48
- {
49
- $json = json_encode($this->languages->getCode('fa'));
50
- $expected = '{"internal_code":"fa","external_code":"fa","english":"Persian","local":"\u0641\u0627\u0631\u0633\u06cc","rtl":true}';
51
- $this->assertEquals($expected, $json);
52
-
53
- $json = json_encode($this->languages->getCode('fr'));
54
- $expected = '{"internal_code":"fr","external_code":"fr","english":"French","local":"Fran\u00e7ais","rtl":false}';
55
- $this->assertEquals($expected, $json);
56
-
57
- $json = json_encode($this->languages->getCode('ar'));
58
- $expected = '{"internal_code":"ar","external_code":"ar","english":"Arabic","local":"\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u200f","rtl":true}';
59
- $this->assertEquals($expected, $json);
60
-
61
- $json = json_encode($this->languages->getCode('he'));
62
- $expected = '{"internal_code":"he","external_code":"he","english":"Hebrew","local":"\u05e2\u05d1\u05e8\u05d9\u05ea","rtl":true}';
63
- $this->assertEquals($expected, $json);
64
-
65
- $json = json_encode($this->languages->getCode('no'));
66
- $expected = '{"internal_code":"no","external_code":"no","english":"Norwegian","local":"Norsk","rtl":false}';
67
- $this->assertEquals($expected, $json);
68
- }
69
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/StatusTest.php DELETED
@@ -1,42 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Client\Client;
4
- use Weglot\Client\Endpoint\Status;
5
-
6
- class StatusTest extends \Codeception\Test\Unit
7
- {
8
- /**
9
- * @var \UnitTester
10
- */
11
- protected $tester;
12
-
13
- /**
14
- * @var Client
15
- */
16
- protected $client;
17
-
18
- /**
19
- * @var Status
20
- */
21
- protected $status;
22
-
23
- /**
24
- * Init client
25
- */
26
- protected function _before()
27
- {
28
- $this->client = new Client(getenv('WG_API_KEY'), 3);
29
- $this->status = new Status($this->client);
30
- }
31
-
32
- // tests
33
- public function testEndpoint()
34
- {
35
- $this->assertTrue($this->status->handle(), 'API not reachable');
36
- }
37
-
38
- public function testPath()
39
- {
40
- $this->assertEquals('/status', $this->status->getPath());
41
- }
42
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/TranslateTest.php DELETED
@@ -1,93 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Client\Client;
4
- use Weglot\Client\Endpoint\Translate;
5
- use Weglot\Client\Api\TranslateEntry;
6
- use Weglot\Client\Api\Enum\BotType;
7
- use Weglot\Client\Api\WordEntry;
8
- use Weglot\Client\Api\Enum\WordType;
9
- use Weglot\Client\Api\WordCollection;
10
-
11
- class TranslateTest extends \Codeception\Test\Unit
12
- {
13
- /**
14
- * @var \UnitTester
15
- */
16
- protected $tester;
17
-
18
- /**
19
- * @var Client
20
- */
21
- protected $client;
22
-
23
- /**
24
- * @var TranslateEntry
25
- */
26
- protected $entry;
27
-
28
- /**
29
- * @var Translate
30
- */
31
- protected $translate;
32
-
33
- /**
34
- * Init client
35
- */
36
- protected function _before()
37
- {
38
- // Client
39
- $this->client = new Client(getenv('WG_API_KEY'), 3);
40
-
41
- // TranslateEntry
42
- $params = [
43
- 'language_from' => 'en',
44
- 'language_to' => 'de',
45
- 'title' => 'Weglot | Translate your website - Multilingual for WordPress, Shopify, ...',
46
- 'request_url' => 'https://weglot.com/',
47
- 'bot' => BotType::HUMAN
48
- ];
49
-
50
- $this->entry = new TranslateEntry($params);
51
- $this->entry->getInputWords()
52
- ->addOne(new WordEntry('This is a blue car', WordType::TEXT))
53
- ->addOne(new WordEntry('This is a black car', WordType::TEXT));
54
-
55
- // Translate endpoint
56
- $this->translate = new Translate($this->entry, $this->client);
57
- }
58
-
59
- // tests
60
- public function testSetOutputWords()
61
- {
62
- $this->entry->setOutputWords(null);
63
- $this->assertTrue($this->entry->getOutputWords() instanceof WordCollection);
64
- $this->assertEquals(0, $this->entry->getOutputWords()->count());
65
- }
66
-
67
- public function testGetParams()
68
- {
69
- $params = $this->entry->getParams();
70
- $this->assertEquals('en', $params['language_from']);
71
- $this->assertEquals('de', $params['language_to']);
72
- $this->assertEquals('https://weglot.com/', $params['request_url']);
73
- $this->assertEquals(BotType::HUMAN, $params['bot']);
74
- }
75
-
76
- public function testEndpointCountWord()
77
- {
78
- $translated = $this->translate->handle();
79
-
80
- $this->assertEquals($this->entry->getInputWords()->count(), $translated->getOutputWords()->count());
81
- }
82
-
83
- public function testTranslateEntry()
84
- {
85
- $this->assertTrue($this->translate->getTranslateEntry() instanceof TranslateEntry);
86
- $this->assertTrue($this->translate->getTranslateEntry() === $this->entry);
87
- }
88
-
89
- public function testPath()
90
- {
91
- $this->assertEquals('/translate', $this->translate->getPath());
92
- }
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Parser/Check/Dom/MetaContentTest.php DELETED
@@ -1,84 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Parser\ConfigProvider\ManualConfigProvider;
4
- use Weglot\Client\Api\Enum\BotType;
5
- use Weglot\Client\Client;
6
- use Weglot\Parser\Parser;
7
-
8
- class MetaContentTest extends \Codeception\Test\Unit
9
- {
10
- /**
11
- * @var \UnitTester
12
- */
13
- protected $tester;
14
-
15
- /**
16
- * @var string
17
- */
18
- protected $url;
19
-
20
- /**
21
- * @var ManualConfigProvider
22
- */
23
- protected $config;
24
-
25
- /**
26
- * @var Client
27
- */
28
- protected $client;
29
-
30
- /**
31
- * @var Parser
32
- */
33
- protected $parser;
34
-
35
- protected $content = '<html><head><title>MyWebPage</title><meta name="description" content="This is my first web page, be kind :)" /><meta</head><body>Coucou</body></html>';
36
-
37
- protected function _before()
38
- {
39
- $this->url = 'https://foo.bar/baz';
40
-
41
- // Config manually
42
- $this->config = new ManualConfigProvider($this->url, BotType::HUMAN);
43
-
44
- // Client
45
- $this->client = new Client(getenv('WG_API_KEY'), 3);
46
- }
47
-
48
- // tests
49
- /*
50
- public function testCheck()
51
- {
52
- // Parser
53
- $this->parser = new Parser($this->client, $this->config);
54
-
55
- // Run the Parser
56
- $translatedContent = $this->parser->translate(
57
- $this->content,
58
- 'en',
59
- 'de'
60
- );
61
-
62
- $old = $this->_getSimpleDom($this->content);
63
- $new = $this->_getSimpleDom($translatedContent);
64
-
65
- $oldContent = $old->find('meta[name="description"]', 0)->content;
66
- $newContent = $new->find('meta[name="description"]', 0)->content;
67
-
68
- $this->assertEquals('This is my first web page, be kind :)', $oldContent);
69
- $this->assertNotEquals($oldContent, $newContent);
70
- }*/
71
-
72
- private function _getSimpleDom($source)
73
- {
74
- return \WGSimpleHtmlDom\str_get_html(
75
- $source,
76
- true,
77
- true,
78
- WG_DEFAULT_TARGET_CHARSET,
79
- false,
80
- WG_DEFAULT_BR_TEXT,
81
- WG_DEFAULT_SPAN_TEXT
82
- );
83
- }
84
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Parser/ParserTest.php DELETED
@@ -1,138 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Parser\ConfigProvider\ServerConfigProvider;
4
- use Weglot\Parser\ConfigProvider\ManualConfigProvider;
5
- use Weglot\Client\Api\Enum\BotType;
6
- use Weglot\Client\Client;
7
- use Weglot\Parser\Parser;
8
- use Weglot\TranslationDefinitions;
9
-
10
- class ParserTest extends \Codeception\Test\Unit
11
- {
12
- /**
13
- * @var \UnitTester
14
- */
15
- protected $tester;
16
-
17
- /**
18
- * @var string
19
- */
20
- protected $url;
21
-
22
- /**
23
- * @var array
24
- */
25
- protected $config;
26
-
27
- /**
28
- * @var Client
29
- */
30
- protected $client;
31
-
32
- /**
33
- * @var Parser
34
- */
35
- protected $parser;
36
-
37
- protected function _before()
38
- {
39
- $this->url = 'https://weglot.com/documentation/getting-started';
40
-
41
- // Config with $_SERVER variables
42
- $_SERVER['SERVER_NAME'] = 'weglot.com';
43
- $_SERVER['REQUEST_URI'] = '/documentation/getting-started';
44
- $_SERVER['HTTPS'] = 'on';
45
- $_SERVER['SERVER_PROTOCOL'] = 'http//';
46
- $_SERVER['SERVER_PORT'] = 443;
47
- $_SERVER['HTTP_USER_AGENT'] = 'Google';
48
-
49
- // Config manually
50
- $this->config = [
51
- 'manual' => new ManualConfigProvider($this->url, BotType::HUMAN),
52
- 'server' => new ServerConfigProvider()
53
- ];
54
-
55
- // Client
56
- $this->client = new Client(getenv('WG_API_KEY'), 3);
57
- }
58
-
59
- // tests
60
- public function testTranslateManual()
61
- {
62
- // Parser
63
- $this->parser = new Parser($this->client, $this->config['manual']);
64
-
65
- // Run the Parser
66
- $translatedContent = $this->parser->translate(
67
- $this->_getContent($this->url),
68
- 'en',
69
- 'de'
70
- );
71
-
72
- $this->assertTrue(\is_string($translatedContent));
73
- }
74
-
75
- public function testTranslateServer()
76
- {
77
- // Parser
78
- $this->parser = new Parser($this->client, $this->config['server']);
79
-
80
- // Run the Parser
81
- $translatedContent = $this->parser->translate(
82
- $this->_getContent($this->url),
83
- 'en',
84
- 'de'
85
- );
86
- $this->assertTrue(\is_string($translatedContent));
87
- }
88
-
89
- public function testParserEngine1NodeSplit()
90
- {
91
- $this->_parserEngineNodeSplit(1);
92
- }
93
-
94
- public function testParserEngine2NodeSplit()
95
- {
96
- $this->_parserEngineNodeSplit(2);
97
- }
98
-
99
- public function testParserEngine3NodeSplit()
100
- {
101
- $this->_parserEngineNodeSplit(3);
102
- }
103
-
104
- public function _parserEngineNodeSplit($version)
105
- {
106
- $cases = TranslationDefinitions::$cases["v" . $version];
107
-
108
- foreach ($cases as $test) {
109
-
110
- // Parser
111
- $client = new Client(getenv('WG_API_KEY') , $version);
112
- $this->parser = new Parser($client, $this->config['server']);
113
-
114
- // Run the Parser
115
- $parsed = $this->parser->parse($test['body']);
116
- $strings = $parsed['words'];
117
-
118
- foreach ($strings as $k => $string) {
119
- $this->assertEquals( $test['expected'][$k]['w'], $string->getWord());
120
- $this->assertEquals( $test['expected'][$k]['t'], $string->getType());
121
- }
122
- $this->assertEquals( count($test['expected']), count($strings));
123
- }
124
- }
125
-
126
-
127
- private function _getContent($url)
128
- {
129
- // Fetching url content
130
- $ch = curl_init($url);
131
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
132
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
133
- $content = curl_exec($ch);
134
- curl_close($ch);
135
-
136
- return $content;
137
- }
138
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Util/JsonLdTest.php DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Util\JsonUtil;
4
- use Weglot\Client\Api\WordCollection;
5
- use Weglot\Client\Api\WordEntry;
6
-
7
- class JsonUtilTest extends \Codeception\Test\Unit
8
- {
9
- /**
10
- * @var \UnitTester
11
- */
12
- protected $tester;
13
-
14
- /**
15
- * @var array
16
- */
17
- protected $json = [];
18
-
19
- protected function _before()
20
- {
21
- $raw = <<<EOT
22
- {
23
- "@context": {
24
- "name": "http://xmlns.com/foaf/0.1/name",
25
- "homepage": {
26
- "@id": "http://xmlns.com/foaf/0.1/workplaceHomepage",
27
- "@type": "@id"
28
- },
29
- "Person": "http://xmlns.com/foaf/0.1/Person"
30
- },
31
- "@id": "http://me.example.com",
32
- "@type": "Person",
33
- "name": "John Smith",
34
- "homepage": "http://www.example.com/"
35
- }
36
- EOT;
37
- $this->json = json_decode($raw, true);
38
- }
39
-
40
-
41
- // tests
42
- public function testGet()
43
- {
44
- $this->assertNull(JsonUtil::get($this->json, 'description'));
45
- $this->assertEquals('John Smith', JsonUtil::get($this->json, 'name'));
46
- }
47
-
48
- public function testAdd()
49
- {
50
- $words = new WordCollection();
51
- $words->addOne(new WordEntry('Une voiture bleue'));
52
-
53
- $this->assertEquals(1, $words->count());
54
-
55
- $value = JsonUtil::get($this->json, 'name');
56
- JsonUtil::add($words, $value);
57
-
58
- $this->assertEquals(2, $words->count());
59
- $this->assertEquals(new WordEntry($value), $words[1]);
60
- }
61
-
62
- public function testSet()
63
- {
64
- $nextJson = 0;
65
- $words = new WordCollection();
66
- $words->addOne(new WordEntry('Une voiture bleue'));
67
-
68
- $this->assertEquals(0, $nextJson);
69
- $this->assertEquals(1, $words->count());
70
-
71
- $data = JsonUtil::set($words, $this->json, 'name', $nextJson);
72
-
73
- $this->assertEquals(1, $nextJson);
74
- $this->assertEquals($data['name'], $words[0]->getWord());
75
- }
76
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Util/RegexTest.php DELETED
@@ -1,85 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Util\Regex;
4
- use Weglot\Util\Regex\RegexEnum;
5
-
6
- class RegexTest extends \Codeception\Test\Unit {
7
- /**
8
- * @var \UnitTester
9
- */
10
- protected $tester;
11
-
12
- /**
13
- * @param array $option
14
- * @return Regex
15
- */
16
- protected function _regexInstance(array $option) {
17
- return new Regex(
18
- $option['type'],
19
- $option['value']
20
- );
21
- }
22
-
23
- public function testRegexStartWith() {
24
- $option = [
25
- 'type' => RegexEnum::START_WITH,
26
- 'value' => 'http://',
27
- ];
28
-
29
- $regex = $this->_regexInstance($option);
30
- $regex = str_replace('/', '\/', $regex->getRegex());
31
-
32
- $this->assertEquals('^http:\/\/', $regex);
33
- $this->assertRegExp("#" . $regex . "#", 'http://');
34
- }
35
-
36
- public function testRegexEndWith() {
37
- $option = [
38
- 'type' => RegexEnum::END_WITH,
39
- 'value' => 'http://',
40
- ];
41
-
42
- $regex = $this->_regexInstance($option);
43
- $regex = str_replace('/', '\/', $regex->getRegex());
44
-
45
- $this->assertEquals('http:\/\/$', $regex);
46
- $this->assertRegExp("#" . $regex . "#", 'test string http://');
47
- }
48
-
49
- public function testRegexContain() {
50
- $option = [
51
- 'type' => RegexEnum::CONTAIN,
52
- 'value' => 'http://',
53
- ];
54
-
55
- $regex = $this->_regexInstance($option);
56
- $regex = str_replace('/', '\/', $regex->getRegex());
57
-
58
- $this->assertEquals('http:\/\/', $regex);
59
- $this->assertRegExp("#" . $regex . "#", 'test http:// string');
60
- }
61
-
62
- public function testRegexIsExactly() {
63
- $option = [
64
- 'type' => RegexEnum::IS_EXACTLY,
65
- 'value' => 'http://',
66
- ];
67
-
68
- $regex = $this->_regexInstance($option);
69
- $regex = str_replace('/', '\/', $regex->getRegex());
70
-
71
- $this->assertEquals('^http:\/\/$', $regex);
72
- $this->assertRegExp("#" . $regex . "#", 'http://');
73
- }
74
- public function testMatchRegex() {
75
- $option = [
76
- 'type' => RegexEnum::MATCH_REGEX,
77
- 'value' => '^http:\/\/',
78
- ];
79
-
80
- $regex = $this->_regexInstance($option)->getRegex();
81
-
82
- $this->assertEquals('^http:\/\/', $regex);
83
- $this->assertRegExp("#" . $regex . "#", 'http://weglot.com');
84
- }
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Util/UrlTest.php DELETED
@@ -1,436 +0,0 @@
1
- <?php
2
-
3
- use Weglot\Util\Url;
4
- use Weglot\Client\Api\LanguageEntry;
5
-
6
- class UrlTest extends \Codeception\Test\Unit
7
- {
8
- /**
9
- * @var \UnitTester
10
- */
11
- protected $tester;
12
-
13
- protected $languages;
14
-
15
- public function __construct($name = null, array $data = [], $dataName = '')
16
- {
17
- $this->languages = array (
18
- 'en' => new LanguageEntry( 'en' , 'en' , 'English' , 'English' , false),
19
- 'fr' => new LanguageEntry( 'fr' , 'fr' , 'French' , 'Français' , false),
20
- 'es' => new LanguageEntry( 'es' , 'es' , 'Spanish' , 'Espanol' , false),
21
- 'de' => new LanguageEntry( 'de' , 'de' , 'German' , 'Deutsch' , false),
22
- 'kr' => new LanguageEntry( 'kr' , 'kr' , 'unknown' , 'unknown' , false),
23
- );
24
- parent::__construct($name, $data, $dataName);
25
- }
26
-
27
- public function testSimpleUrlDefaultEnWithEsUrl()
28
- {
29
- $profile = [
30
- 'url' => 'https://weglot.com/es/pricing',
31
- 'default' => $this->languages['en'],
32
- 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
33
- 'prefix' => '',
34
- 'exclude' => [],
35
- 'results' => [
36
- 'getHost' => 'https://weglot.com',
37
- 'getPathPrefix' => '',
38
- 'getPath' => '/pricing',
39
- 'getCurrentLanguage' => $this->languages['es'],
40
- 'detectBaseUrl' => 'https://weglot.com/pricing',
41
- 'getAllUrls' => [
42
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/pricing'),
43
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/fr/pricing'),
44
- array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com/de/pricing'),
45
- array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com/es/pricing')
46
- ]
47
- ]
48
- ];
49
-
50
- $url = $this->_urlInstance($profile);
51
- $this->_checkResults($url, $profile);
52
- }
53
-
54
- public function testSimpleUrlDefaultFrWithEnUrl()
55
- {
56
- $profile = [
57
- 'url' => 'https://www.ratp.fr/en/horaires',
58
- 'default' => $this->languages['fr'],
59
- 'languages' => [ $this->languages['en']],
60
- 'prefix' => '',
61
- 'exclude' => [],
62
- 'results' => [
63
- 'getHost' => 'https://www.ratp.fr',
64
- 'getPathPrefix' => '',
65
- 'detectBaseUrl' => 'https://www.ratp.fr/horaires',
66
- 'getPath' => '/horaires',
67
- 'getCurrentLanguage' => $this->languages['en'],
68
- 'getAllUrls' => [
69
- array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr/horaires'),
70
- array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr/en/horaires'),
71
- ]
72
- ]
73
- ];
74
-
75
- $url = $this->_urlInstance($profile);
76
- $this->_checkResults($url, $profile);
77
- }
78
-
79
- public function testSimpleUrlDefaultFrWithEnUrlAndCustomPort()
80
- {
81
- $profile = [
82
- 'url' => 'https://www.ratp.fr:3000/en/horaires',
83
- 'default' => $this->languages['fr'],
84
- 'languages' => [ $this->languages['en']],
85
- 'prefix' => '',
86
- 'exclude' => [],
87
- 'results' => [
88
- 'getHost' => 'https://www.ratp.fr:3000',
89
- 'getPathPrefix' => '',
90
- 'detectBaseUrl' => 'https://www.ratp.fr:3000/horaires',
91
- 'getPath' => '/horaires',
92
- 'getCurrentLanguage' => $this->languages['en'],
93
- 'getAllUrls' => [
94
- array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr:3000/horaires'),
95
- array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr:3000/en/horaires'),
96
- ]
97
- ]
98
- ];
99
-
100
- $url = $this->_urlInstance($profile);
101
- $this->_checkResults($url, $profile);
102
- }
103
-
104
- public function testSimpleUrlDefaultFrWithFrUrl()
105
- {
106
- $profile = [
107
- 'url' => 'https://www.ratp.fr/horaires',
108
- 'default' => $this->languages['fr'],
109
- 'languages' => [ $this->languages['en']],
110
- 'prefix' => '',
111
- 'exclude' => [],
112
- 'results' => [
113
- 'getHost' => 'https://www.ratp.fr',
114
- 'getPathPrefix' => '',
115
- 'detectBaseUrl' => 'https://www.ratp.fr/horaires',
116
- 'getPath' => '/horaires',
117
- 'getCurrentLanguage' => $this->languages['fr'],
118
- 'getAllUrls' => [
119
- array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr/horaires'),
120
- array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr/en/horaires')
121
- ]
122
- ]
123
- ];
124
-
125
- $url = $this->_urlInstance($profile);
126
- $this->_checkResults($url, $profile);
127
- }
128
-
129
- public function testUrlDefaultEnWithEsUrlAndPrefix()
130
- {
131
- $profile = [
132
- 'url' => 'https://weglot.com/web/es/pricing',
133
- 'default' => $this->languages['en'],
134
- 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
135
- 'prefix' => '/web',
136
- 'exclude' => [],
137
- 'results' => [
138
- 'getHost' => 'https://weglot.com',
139
- 'getPathPrefix' => '/web',
140
- 'getPath' => '/pricing',
141
- 'getCurrentLanguage' => $this->languages['es'],
142
- 'detectBaseUrl' => 'https://weglot.com/web/pricing',
143
- 'getAllUrls' => [
144
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/web/pricing'),
145
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/web/fr/pricing'),
146
- array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com/web/de/pricing'),
147
- array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com/web/es/pricing')
148
- ]
149
- ]
150
- ];
151
-
152
- $url = $this->_urlInstance($profile);
153
- $this->_checkResults($url, $profile);
154
- }
155
-
156
- public function testUrlDefaultEnWithEsUrlAndTrailingSlashAndPrefix()
157
- {
158
- $profile = [
159
- 'url' => 'http://weglotmultiv2.local/othersite/',
160
- 'default' => $this->languages['en'],
161
- 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
162
- 'prefix' => '/othersite',
163
- 'exclude' => [],
164
- 'results' => [
165
- 'getHost' => 'http://weglotmultiv2.local',
166
- 'getPathPrefix' => '/othersite',
167
- 'getPath' => '/',
168
- 'getCurrentLanguage' => $this->languages['en'],
169
- 'detectBaseUrl' => 'http://weglotmultiv2.local/othersite/',
170
- 'getAllUrls' => [
171
- array( 'language' => $this->languages['en'], 'url' => 'http://weglotmultiv2.local/othersite/'),
172
- array( 'language' => $this->languages['fr'], 'url' => 'http://weglotmultiv2.local/othersite/fr/'),
173
- array( 'language' => $this->languages['de'], 'url' => 'http://weglotmultiv2.local/othersite/de/'),
174
- array( 'language' => $this->languages['es'], 'url' => 'http://weglotmultiv2.local/othersite/es/')
175
- ]
176
- ]
177
- ];
178
-
179
- $url = $this->_urlInstance($profile);
180
- $this->_checkResults($url, $profile);
181
- }
182
-
183
- public function testUrlDefaultEnWithEnUrlAndPrefixAsUrl()
184
- {
185
- $profile = [
186
- 'url' => 'https://weglot.com/web',
187
- 'default' => $this->languages['en'],
188
- 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
189
- 'prefix' => '/web',
190
- 'exclude' => [],
191
- 'results' => [
192
- 'getHost' => 'https://weglot.com',
193
- 'getPathPrefix' => '/web',
194
- 'getPath' => '/',
195
- 'getCurrentLanguage' => $this->languages['en'],
196
- 'detectBaseUrl' => 'https://weglot.com/web/',
197
- 'getAllUrls' => [
198
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/web/'),
199
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/web/fr/'),
200
- array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com/web/de/'),
201
- array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com/web/es/')
202
- ]
203
- ]
204
- ];
205
-
206
- $url = $this->_urlInstance($profile);
207
- $this->_checkResults($url, $profile);
208
- }
209
-
210
- public function testUrlDefaultEnWithEnUrlAndPrefixAsUrlAndCustomPort()
211
- {
212
- $profile = [
213
- 'url' => 'https://weglot.com:8080/web/es/',
214
- 'default' => $this->languages['en'],
215
- 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
216
- 'prefix' => '/web',
217
- 'exclude' => [],
218
- 'results' => [
219
- 'getHost' => 'https://weglot.com:8080',
220
- 'getPathPrefix' => '/web',
221
- 'getPath' => '/',
222
- 'getCurrentLanguage' => $this->languages['es'],
223
- 'detectBaseUrl' => 'https://weglot.com:8080/web/',
224
- 'getAllUrls' => [
225
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com:8080/web/'),
226
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com:8080/web/fr/'),
227
- array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com:8080/web/de/'),
228
- array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com:8080/web/es/')
229
- ]
230
- ]
231
- ];
232
-
233
- $url = $this->_urlInstance($profile);
234
- $this->_checkResults($url, $profile);
235
- }
236
-
237
- public function testUrlDefaultEnWithFrAndExclude()
238
- {
239
- $profile = [
240
- 'url' => 'https://weglot.com/fr/pricing',
241
- 'default' => $this->languages['en'],
242
- 'languages' => [ $this->languages['fr'], $this->languages['kr']],
243
- 'prefix' => '',
244
- 'exclude' => [
245
- [ '\/admin\/.*' , null ]
246
- ],
247
- 'results' => [
248
- 'getHost' => 'https://weglot.com',
249
- 'getPathPrefix' => '',
250
- 'getPath' => '/pricing',
251
- 'getCurrentLanguage' => $this->languages['fr'],
252
- 'detectBaseUrl' => 'https://weglot.com/pricing',
253
- 'getAllUrls' => [
254
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/pricing'),
255
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/fr/pricing'),
256
- array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/kr/pricing')
257
- ]
258
- ]
259
- ];
260
-
261
- $url = $this->_urlInstance($profile);
262
- $this->_checkResults($url, $profile);
263
-
264
- $profile['url'] = 'https://weglot.com/fr/admin/dashboard';
265
- $profile['results']['getPath'] = '/admin/dashboard';
266
- $profile['results']['detectBaseUrl'] = 'https://weglot.com/admin/dashboard';
267
- $profile['results']['getAllUrls'] = [
268
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/admin/dashboard'),
269
- ];
270
-
271
- $url = $this->_urlInstance($profile);
272
- $this->_checkResults($url, $profile);
273
- }
274
-
275
- public function testUrlDefaultEnWithKrAndInverseExclude()
276
- {
277
- $profile = [
278
- 'url' => 'https://weglot.com/kr/pricing',
279
- 'default' => $this->languages['en'],
280
- 'languages' => [ $this->languages['fr'], $this->languages['kr']],
281
- 'prefix' => '',
282
- 'exclude' => [
283
- ['^(?!/rgpd-wordpress/?|/optimiser-wordpress/?).*$' , null ]
284
- ],
285
- 'results' => [
286
- 'getHost' => 'https://weglot.com',
287
- 'getPathPrefix' => '',
288
- 'getPath' => '/pricing',
289
- 'getCurrentLanguage' => $this->languages['kr'],
290
- 'detectBaseUrl' => 'https://weglot.com/pricing',
291
- 'getAllUrls' => [
292
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/pricing'),
293
- ] // because it's excluded
294
- ]
295
- ];
296
-
297
- $url = $this->_urlInstance($profile);
298
- $this->_checkResults($url, $profile);
299
-
300
- $profile['url'] = 'https://weglot.com/kr/rgpd-wordpress';
301
- $profile['results']['getPath'] = '/rgpd-wordpress';
302
- $profile['results']['detectBaseUrl'] = 'https://weglot.com/rgpd-wordpress';
303
- $profile['results']['getAllUrls'] = [
304
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/rgpd-wordpress'),
305
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/fr/rgpd-wordpress'),
306
- array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/kr/rgpd-wordpress')
307
- ];
308
-
309
- $url = $this->_urlInstance($profile);
310
- $this->_checkResults($url, $profile);
311
- }
312
-
313
- public function testUrlDefaultEnWithFrAndPrefixAndExclude()
314
- {
315
- $profile = [
316
- 'url' => 'https://weglot.com/landing/fr/how-to-manage-your-translations',
317
- 'default' => $this->languages['en'],
318
- 'languages' => [ $this->languages['fr'], $this->languages['kr']],
319
- 'prefix' => '/landing',
320
- 'exclude' => [
321
- '\/admin\/.*'
322
- ],
323
- 'results' => [
324
- 'getHost' => 'https://weglot.com',
325
- 'getPathPrefix' => '/landing',
326
- 'getPath' => '/how-to-manage-your-translations',
327
- 'getCurrentLanguage' => $this->languages['fr'],
328
- 'detectBaseUrl' => 'https://weglot.com/landing/how-to-manage-your-translations',
329
- 'getAllUrls' => [
330
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/landing/how-to-manage-your-translations'),
331
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/landing/fr/how-to-manage-your-translations'),
332
- array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/landing/kr/how-to-manage-your-translations')
333
- ]
334
- ]
335
- ];
336
-
337
- $url = $this->_urlInstance($profile);
338
- $this->_checkResults($url, $profile);
339
-
340
- $profile['url'] = 'https://weglot.com/landing/fr/admin/how-to-manage-your-translations';
341
- $profile['results']['getPath'] = '/admin/how-to-manage-your-translations';
342
- $profile['results']['detectBaseUrl'] = 'https://weglot.com/landing/admin/how-to-manage-your-translations';
343
- $profile['results']['getAllUrls'] = [
344
- array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/landing/admin/how-to-manage-your-translations'),
345
- array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/landing/fr/admin/how-to-manage-your-translations'),
346
- array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/landing/kr/admin/how-to-manage-your-translations')
347
- ];
348
-
349
- $url = $this->_urlInstance($profile);
350
- $this->_checkResults($url, $profile);
351
- }
352
-
353
- public function testSimpleUrlDefaultFrWithEnUrlAndQuery()
354
- {
355
- $profile = [
356
- 'url' => 'https://www.ratp.fr/en/horaires?from=2018-06-04&to=2018-06-05',
357
- 'default' => $this->languages['fr'],
358
- 'languages' => [ $this->languages['en']],
359
- 'prefix' => '',
360
- 'exclude' => [],
361
- 'results' => [
362
- 'getHost' => 'https://www.ratp.fr',
363
- 'getPathPrefix' => '',
364
- 'detectBaseUrl' => 'https://www.ratp.fr/horaires?from=2018-06-04&to=2018-06-05',
365
- 'getPath' => '/horaires',
366
- 'getCurrentLanguage' => $this->languages['en'],
367
- 'getAllUrls' => [
368
- array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr/horaires?from=2018-06-04&to=2018-06-05'),
369
- array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr/en/horaires?from=2018-06-04&to=2018-06-05'),
370
- ]
371
- ]
372
- ];
373
-
374
- $url = $this->_urlInstance($profile);
375
- $this->_checkResults($url, $profile);
376
- }
377
-
378
- /**
379
- * @param array $profile
380
- * @return Url
381
- */
382
- protected function _urlInstance(array $profile)
383
- {
384
- return (new Url(
385
- $profile['url'],
386
- $profile['default'],
387
- $profile['languages'],
388
- $profile['prefix'],
389
- $profile['exclude'],
390
- null
391
- ));
392
- }
393
-
394
- /**
395
- * @param array $currentRequestAllUrls
396
- * @return string
397
- */
398
- protected function _generateHrefLangs(array $currentRequestAllUrls)
399
- {
400
- $render = '';
401
- foreach ($currentRequestAllUrls as $urlArray) {
402
- $render .= '<link rel="alternate" href="' .$urlArray['url']. '" hreflang="' .$urlArray['language']->getExternalCode(). '"/>'."\n";
403
- }
404
- return $render;
405
- }
406
-
407
- /**
408
- * @param Url $url
409
- * @param array $profile
410
- * @return void
411
- */
412
- protected function _checkResults(Url $url, array $profile)
413
- {
414
- // cloned $url, to be sure to have a `null` $baseUrl
415
- $cloned = clone $url;
416
- $this->assertEquals($profile['results']['getAllUrls'], $cloned->getAllUrls());
417
-
418
- // cloned $url, to be sure to have a `null` $baseUrl
419
- $cloned = clone $url;
420
-
421
- $this->assertEquals($profile['results']['detectBaseUrl'], $url->detectUrlDetails());
422
-
423
- $this->assertEquals($profile['results']['getHost'], $url->getHost());
424
- $this->assertEquals($profile['results']['getPathPrefix'], $url->getPathPrefix());
425
- $this->assertEquals($profile['results']['getPath'], $url->getPath());
426
-
427
- $this->assertEquals($profile['results']['getCurrentLanguage'], $url->getCurrentLanguage());
428
-
429
- $this->assertEquals($profile['results']['getAllUrls'], $url->getAllUrls());
430
- //$this->assertEquals($this->_generateHrefLangs($profile['results']['getAllUrls']), $url->generateHrefLangsTags());
431
-
432
- foreach ($profile['results']['getAllUrls'] as $urlArray) {
433
- $this->assertEquals($urlArray['url'], $url->getForLanguage($urlArray['language']));
434
- }
435
- }
436
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
weglot.php CHANGED
@@ -7,7 +7,7 @@ Author: Weglot Translate team
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
- Version: 3.4
11
  */
12
 
13
  /**
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  define( 'WEGLOT_NAME', 'Weglot' );
23
  define( 'WEGLOT_SLUG', 'weglot-translate' );
24
  define( 'WEGLOT_OPTION_GROUP', 'group-weglot-translate' );
25
- define( 'WEGLOT_VERSION', '3.4' );
26
  define( 'WEGLOT_PHP_MIN', '5.6' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
+ Version: 3.5
11
  */
12
 
13
  /**
22
  define( 'WEGLOT_NAME', 'Weglot' );
23
  define( 'WEGLOT_SLUG', 'weglot-translate' );
24
  define( 'WEGLOT_OPTION_GROUP', 'group-weglot-translate' );
25
+ define( 'WEGLOT_VERSION', '3.5' );
26
  define( 'WEGLOT_PHP_MIN', '5.6' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );