Skip to content

Commit

Permalink
Option 'Show language names in "Camel Case"'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnclause committed Oct 19, 2015
1 parent c35975d commit ed18810
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 53 deletions.
2 changes: 1 addition & 1 deletion admin/qtx_activation_hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ function qtranxf_admin_notices_survey_request(){


function qtranxf_admin_notices_errors(){
//qtranxf_dbg_log('"admin_notices": qtranxf_admin_notices_errors: REQUEST_TIME_FLOAT: ', $_SERVER['REQUEST_TIME_FLOAT']);
//qtranxf_dbg_log('14.qtranxf_admin_notices_errors:');
$msgs = get_option('qtranslate_config_errors');
if(!is_array($msgs)) return;
foreach($msgs as $key => $msg){
Expand Down
22 changes: 12 additions & 10 deletions admin/qtx_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function qtranxf_collect_translations_posted() {

function qtranxf_admin_load()
{
//qtranxf_dbg_log('qtranxf_admin_load:');
//qtranxf_dbg_log('1.4.qtranxf_admin_load:');
qtranxf_admin_loadConfig();
$bnm = qtranxf_plugin_basename();
add_filter( 'plugin_action_links_'.$bnm, 'qtranxf_links', 10, 4);
Expand All @@ -129,6 +129,7 @@ function qtranxf_admin_load()
qtranxf_admin_load();

function qtranxf_load_admin_page_config(){
//qtranxf_dbg_log('1.8.qtranxf_load_admin_page_config:');
$page_configs = qtranxf_get_admin_page_config();
if(!empty($page_configs['']['filters'])){
qtranxf_add_filters($page_configs['']['filters']);
Expand All @@ -137,6 +138,7 @@ function qtranxf_load_admin_page_config(){

function qtranxf_admin_init(){
global $q_config, $pagenow;
//qtranxf_dbg_log('5.qtranxf_admin_init:');

add_action('admin_notices', 'qtranxf_admin_notices_config');

Expand Down Expand Up @@ -177,19 +179,17 @@ function qtranxf_admin_init(){
//qtranxf_updateSlug();
}
}
//add_action('qtranslate_init_begin','qtranxf_admin_init');
add_action('admin_init','qtranxf_admin_init',2);

/**
* load field configurations for the current admin page
*/
function qtranxf_get_admin_page_config() {
static $page_configs;//cache
if($page_configs){
//qtranxf_dbg_log('qtranxf_get_admin_page_config: $page_configs: cached: ', $page_configs);
return $page_configs;
}
global $q_config, $pagenow;
if(isset($q_config['i18n-cache']['admin_page_configs'])){
//qtranxf_dbg_log('qtranxf_get_admin_page_config: $page_configs cached: ', $q_config['i18n-cache']['admin_page_configs']);
return $q_config['i18n-cache']['admin_page_configs'];
}
$admin_config = $q_config['admin_config'];
//qtranxf_dbg_log('qtranxf_get_admin_page_config: $admin_config: raw: ',qtranxf_json_encode($admin_config));
$admin_config = apply_filters('qtranslate_load_admin_page_config',$admin_config);//obsolete
Expand All @@ -203,6 +203,7 @@ function qtranxf_get_admin_page_config() {

$page_configs = qtranxf_parse_page_config($admin_config, $pagenow, $url_query);
//qtranxf_dbg_log('qtranxf_get_admin_page_config: $page_configs: ', $page_configs);
$q_config['i18n-cache']['admin_page_configs'] = $page_configs;
return $page_configs;
}

Expand Down Expand Up @@ -312,6 +313,7 @@ function qtranxf_get_admin_page_config_post_type($post_type) {
foreach($page_config['js'] as $k => $js){
if(!isset($js['src'])) continue;
$src = $js['src'];
//qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: js['.$k.']: $src: ',$src);
if( $src[0] == '.' && ($src[1] == '/' || $src[1] == DIRECTORY_SEPARATOR) ){
$page_config['js'][$k]['src'] = $bnm.substr($src,1);
}else{
Expand Down Expand Up @@ -395,8 +397,6 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) {
$config['page_config'] = $page_config;
//no need for javascript:
unset($config['page_config']['js']);
//unset($config['page_config']['js-conf']);
//unset($config['page_config']['js-exec']);
}

$config['LSB'] = $q_config['editor_mode'] == QTX_EDITOR_MODE_LSB;
Expand Down Expand Up @@ -518,6 +518,7 @@ function qtranxf_add_admin_css () {
}

function qtranxf_admin_head() {
//qtranxf_dbg_log('11.qtranxf_admin_head:');
//wp_enqueue_script( 'jquery' );
//qtranxf_add_css();//Since 3.2.5 no longer needed
qtranxf_add_admin_css();
Expand All @@ -526,7 +527,7 @@ function qtranxf_admin_head() {
add_action('admin_head', 'qtranxf_admin_head');

function qtranxf_admin_footer() {
//qtranxf_dbg_log('qtranxf_admin_footer:');
//qtranxf_dbg_log('18.qtranxf_admin_footer:');
$enqueue_script = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG);
//$enqueue_script = false;
qtranxf_add_admin_footer_js( $enqueue_script );
Expand Down Expand Up @@ -576,6 +577,7 @@ function qtranxf_translate_menu(&$m) {
*/
function qtranxf_admin_menu() {
global $menu, $submenu;
//qtranxf_dbg_log('7.qtranxf_admin_menu:');
if(!empty($menu)){
qtranxf_translate_menu($menu);
}
Expand Down
30 changes: 19 additions & 11 deletions admin/qtx_admin_options_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,18 +610,28 @@ function qtranxf_parse_post_type_excluded() {

function qtranxf_updateSettings(){
global $qtranslate_options, $q_config;
//$errors = array();

$errors = &$q_config['url_info']['errors'];

// update front settings

/**
* Opportunity to prepare special custom settings update on sub-plugins
*/
do_action('qtranslate_update_settings_pre');

// special cases handling for front options

qtranxf_updateSetting('default_language', QTX_LANGUAGE);
//enabled_languages are not changed at this place

qtranxf_updateSettingFlagLocation('flag_location');
qtranxf_updateSettingIgnoreFileTypes('ignore_file_types');

$_POST['language_name_case'] = isset($_POST['camel_case']) ? '0' : '1';

// special cases handling for front options - end

foreach($qtranslate_options['front']['int'] as $nm => $def){
qtranxf_updateSetting($nm, QTX_INTEGER, $def);
}
Expand Down Expand Up @@ -667,7 +677,7 @@ function qtranxf_updateSettings(){

// update admin settings

//special cases handling
//special cases handling for admin options

if(isset($_POST['json_config_files'])){
//verify that files are loadable
Expand Down Expand Up @@ -721,6 +731,8 @@ function qtranxf_updateSettings(){

qtranxf_parse_post_type_excluded();

//special cases handling for admin options - end

do_action('qtranslate_update_settings_admin');

foreach($qtranslate_options['admin']['int'] as $nm => $def){
Expand All @@ -746,15 +758,11 @@ function qtranxf_updateSettings(){
if(empty($_POST['json_config_files']))//only update if config files parsed successfully
qtranxf_update_i18n_config();

/*
if(isset($q_config['url_info']['errors'])){
foreach($q_config['url_info']['errors'] as $msg){
$errors[] = $msg;
}
unset($q_config['url_info']['errors']);//todo error handling needs to be cleaned up
}
return $errors;
*/
$q_config['i18n-cache'] = array();//clear i18n-config cache

/**
* Opportunity to update special custom settings on sub-plugins
*/
do_action('qtranslate_update_settings');
}

Expand Down
7 changes: 7 additions & 0 deletions admin/qtx_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ function qtranxf_conf() {
<p class="qtranxs_notes"><?php printf(__('When a page or a post with an untranslated content is viewed, a message with a list of other available languages is displayed, in which languages are ordered as defined by option "%s". If this option is on, then the content of the first available language will also be shown, instead of the expected language, for the sake of user convenience.', 'qtranslate'), __('Default Language / Order', 'qtranslate')) ?></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Language Names', 'qtranslate') ?></th>
<td>
<label for="camel_case"><input type="checkbox" name="camel_case" id="camel_case" value="1"<?php checked(!isset($q_config['language_name_case']) || !$q_config['language_name_case']) ?>/> <?php _e('Show language names in "Camel Case".', 'qtranslate') ?></label>
<p class="qtranxs_notes"><?php printf(__('Define how to display translated language names, whenever languages need to be listed, for example, in "%s" statement.', 'qtranslate'), __('Not Available Message', 'qtranslate')) ?></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Detect Browser Language', 'qtranslate') ?></th>
<td>
Expand Down
4 changes: 2 additions & 2 deletions qtranslate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: qTranslate-X
Plugin URI: http://wordpress.org/plugins/qtranslate-x/
Description: Adds user-friendly and database-friendly multilingual content support.
Version: 3.4.6.4
Version: 3.4.6.5
Author: qTranslate Team
Author URI: http://qtranslatexteam.wordpress.com/about
Tags: multilingual, multi, language, admin, tinymce, Polyglot, bilingual, widget, switcher, professional, human, translation, service, qTranslate, zTranslate, mqTranslate, qTranslate Plus, WPML
Expand Down Expand Up @@ -118,7 +118,7 @@
* Designed as interface for other plugin integration. The documentation is available at
* https://qtranslatexteam.wordpress.com/integration/
*/
define('QTX_VERSION','3.4.6.4');
define('QTX_VERSION','3.4.6.5');

if ( ! defined( 'QTRANSLATE_FILE' ) ) {
define( 'QTRANSLATE_FILE', __FILE__ );
Expand Down
35 changes: 7 additions & 28 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

function qtranxf_init_language() {
global $q_config, $pagenow;
//qtranxf_dbg_log('"plugins_loaded(2)": qtranxf_init_language: REQUEST_TIME_FLOAT: ', $_SERVER['REQUEST_TIME_FLOAT']);
//qtranxf_dbg_log('1.qtranxf_init_language:');

//if(defined('QTRANS_INIT')){
// //qtranxf_dbg_log('qtranxf_init_language: QTRANS_INIT: url_info: ',$q_config['url_info']);
Expand Down Expand Up @@ -465,39 +465,18 @@ function qtranxf_load_option_qtrans_compatibility(){
require_once(dirname(__FILE__).'/qtranslate_compatibility.php');
}

/** Is in use by 3rd-party plugins (for example, alo_easymail) to test q-X presence,
* which they should have done by testing "if ( defined( 'QTRANSLATE_FILE' )"
/**
* Response to action 'init', which runs after user is authenticated.
* Currently unused.
* Is in use by 3rd-party plugins (for example, alo_easymail) to test q-X presence,
* which they should have done by testing "if ( defined( 'QTRANSLATE_FILE' )" instead.
* @since 3.4
*/
function qtranxf_init() {
//qtranxf_dbg_log('"init": qtranxf_init: REQUEST_TIME_FLOAT: ', $_SERVER['REQUEST_TIME_FLOAT']);
//qtranxf_dbg_log('3.qtranxf_init:');
}
add_action('init', 'qtranxf_init',2);//user is authenticated

/* //use action 'init' in front-end and/or action 'admin_init' admin-end accordingly
* Response to action 'init', which runs after user is authenticated
* /
function qtranxf_init() {
global $q_config;
do_action('qtranslate_init_begin');
//// Check for WP Secret Key Mismatch
//global $wp_default_secret_key;
//if(strpos($q_config['url_info']['url'],'wp-login.php')!==false && defined('AUTH_KEY') && isset($wp_default_secret_key) && $wp_default_secret_key != AUTH_KEY) {
// global $error;
// $error = __('Your $wp_default_secret_key is mismatching with your AUTH_KEY. This might cause you not to be able to login anymore.', 'qtranslate');
//}
//if($q_config['url_info']['doing_front_end']){
// do_action('qtranslate_init_front');
//}
//allow other plugins to initialize whatever they need for qTranslate
do_action('qtranslate_init');
}
*/

function qtranxf_front_header_css_default(){
global $q_config;
$flag_location=qtranxf_flag_location();
Expand Down
1 change: 1 addition & 0 deletions qtranslate_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function qtranxf_set_default_options(&$ops)
'url_mode' => QTX_URL_PATH,// sets default url mode
'use_strftime' => QTX_DATE,// strftime usage (backward compability)
'filter_options_mode' => QTX_FILTER_OPTIONS_ALL,
'language_name_case' => 0 //Camel Case
);

$ops['front']['bool']=array(
Expand Down
10 changes: 9 additions & 1 deletion qtranslate_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,15 @@ function qtranxf_getLanguageName($lang = ''){
return $q_config['language-names'][$lang] = $q_config['language_name'][$lang];
}
$n = $translations->entries[$locale]->translations[0];
return $q_config['language-names'][$lang] = mb_convert_case($n,MB_CASE_TITLE);
if(empty($q_config['language_name_case'])){//Camel Case by default
if(function_exists('mb_convert_case')){// module 'mbstring' may not be installed by default: https://wordpress.org/support/topic/qtranslate_utilsphp-on-line-504
$n = mb_convert_case($n,MB_CASE_TITLE);
}else{
$msg = 'qTranslate-X: Enable PHP module "mbstring" to get names of languages printed in "Camel Case" or disable option \'Show language names in "Camel Case"\' on admin page '.admin_url('options-general.php?page=qtranslate-x#general').'. You may find more information at http://php.net/manual/en/mbstring.installation.php, or search for PHP installation options on control panel of your server provider.';
error_log($msg);
}
}
return $q_config['language-names'][$lang] = $n;
}

function qtranxf_isEnabled($lang) {
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ Developers: please drop new topics here, the text will be moved to [qTranslate-X

## Upgrade Notice ##

### 3.4.6.5 ###
Fix: Handling the lack of PHP function `mb_convert_case`, as PHP module `mbstring` may not be installed by default.

### 3.4.6.4 ###
Fix: A fix for Internal Server Error 500 under some circumstances.

Expand All @@ -108,6 +111,9 @@ This version recovers translation of parent of a category on category edit page.

## Changelog ##

### 3.4.6.5 ###
* Improvement: Option 'Show language names in "Camel Case"' has been added on Settings/Languages page `/wp-admin/options-general.php?page=qtranslate-x#general` in order to handle absence of function `mb_convert_case`, as PHP module `mbstring` may not be installed by default: [WP Topic](https://wordpress.org/support/topic/qtranslate_utilsphp-on-line-504).

### 3.4.6.4 ###
* Enhancement: The list of avalable languages in "Not Available Message" and alternative language shown now follow the order of languges defined on configuration page, ignoring the default language. For example, if the first language in the order is English, the second is your native and the default, then English translation will be preferably shown as alternative language. Most sites are expected to be unaffected, since the first language in the order is normally the default langauge. However, it may make sense to first try to show most common language (like English in this example), instead of the default language. Now this is possible with putting the most common language to be the first in the order of languages. The order affects language menu, widget and language shown when translation is not available, as well as any other place where languages need to be listed in an order.
* Fix: `home_url()` on admin side is now only filtered on `/wp-admin/customize.php` page, otherwise it created a few problems, for example, wrong overwriting of `.htaccess` file in some cases, causing Internal Server Error 500 with infinite redirection loop: [WP Topic](https://wordpress.org/support/topic/internal-server-error-500-after-346-update).
Expand Down

0 comments on commit ed18810

Please sign in to comment.