コード例 #1
0
function qtranxf_test_dt_format($cfg, $cfg_name = 'dtf', $format = 'F j, Y')
{
    global $q_config;
    $q_config['locale'] = array_merge(qtranxf_default_locale(), $q_config['locale']);
    $enabled_languages = $q_config['enabled_languages'];
    require_once QTRANSLATE_DIR . '/admin/qtx_admin_options_update.php';
    $t = strtotime('Nov 16, 2014 3:04pm');
    //qtranxf_dbg_log('qtranxf_test_dt_format: $t: ',$t);
    $m = PHP_EOL;
    foreach ($cfg as $c => $f) {
        if (!in_array($c, $q_config['enabled_languages'])) {
            $q_config['enabled_languages'][] = $c;
        }
        qtranxf_updateGettextDatabases(true, $c);
        $d = qtranxf_translate_dt_format($format, $c);
        //$d = qtranxf_convert_strftime2date($f);
        $sd = date($d, $t);
        $m .= '$' . $cfg_name . '[\'' . $c . '\'] = \'' . $d . '\';// "' . $sd . '"';
        if (false) {
            require_once QTRANSLATE_DIR . '/inc/qtx_date_time.php';
            $ff = qtranxf_convertDateFormatToStrftimeFormat($f);
            $sf = qtranxf_strftime($ff, $t);
            $m .= ' // strftime("' . $f . '") "' . ($sf ? $sf : 'invalid') . '"';
        }
        $m .= PHP_EOL;
    }
    $q_config['enabled_languages'] = $enabled_languages;
    //qtranxf_dbg_log('qtranxf_test_dt_format("'.$cfg_name.'","'.$format.'"): $m:'.$m);
    return $m;
}
コード例 #2
0
function qtranxf_set_date_i18n_format(&$cfg, $lang, $name, $format)
{
    $changed = false;
    $date_i18n =& $cfg['date_i18n'];
    if (!empty($date_i18n[$name]) && $format != $date_i18n[$name]) {
        $f = $date_i18n[$name];
        $fmts = $date_i18n[$f];
        $date_i18n[$format] = $fmts;
        unset($date_i18n[$f]);
        $changed = true;
    }
    if (empty($date_i18n[$name]) || $date_i18n[$name] != $format) {
        $date_i18n[$name] = $format;
        $changed = true;
    }
    if (empty($cfg[$name][$lang])) {
        $lng_format = qtranxf_translate_dt_format($name, $lang);
    } else {
        $lng_format = qtranxf_convert_strftime2date($cfg[$name][$lang]);
    }
    if (empty($lng_format) || $lng_format == $format) {
        if (isset($date_i18n[$format][$lang])) {
            unset($date_i18n[$format][$lang]);
            $changed = true;
        }
    } else {
        if (empty($date_i18n[$format][$lang]) || $date_i18n[$format][$lang] != $lng_format) {
            $date_i18n[$format][$lang] = $lng_format;
            $changed = true;
        }
    }
    return $changed;
}
コード例 #3
0
function qtranxf_language_form()
{
    global $q_config;
    $language_code = isset($q_config['posted']['language_code']) ? $q_config['posted']['language_code'] : '';
    $original_lang = isset($q_config['posted']['original_lang']) ? $q_config['posted']['original_lang'] : '';
    $lang_props = isset($q_config['posted']['lang_props']) ? $q_config['posted']['lang_props'] : array();
    $language_flag = isset($lang_props['flag']) ? $lang_props['flag'] : '';
    $language_name = isset($lang_props['language_name']) ? $lang_props['language_name'] : '';
    $language_locale = isset($lang_props['locale']) ? $lang_props['locale'] : '';
    if ($original_lang) {
        $language_locale_html = isset($lang_props['locale_html']) ? $lang_props['locale_html'] : '';
        $language_date_format = isset($lang_props['date_format']) ? $lang_props['date_format'] : qtranxf_translate_dt_format('date_format', $language_code);
        $language_time_format = isset($lang_props['time_format']) ? $lang_props['time_format'] : qtranxf_translate_dt_format('time_format', $language_code);
        if (empty($lang_props['not_available'])) {
            $nams = qtranxf_language_configured('not_available');
            if (!empty($nams[$original_lang])) {
                $language_na_message = $nams[$original_lang];
            } else {
                $language_na_message = __('Sorry, this entry is only available in %LANG:, : and %.', 'qtranslate');
            }
        } else {
            $language_na_message = $lang_props['not_available'];
        }
        if ($q_config['use_strftime'] == QTX_DATE_WP) {
            $language_date_format = qtranxf_convert_strftime2date($language_date_format);
            $language_time_format = qtranxf_convert_strftime2date($language_time_format);
        }
        if (!empty($_GET['msg'])) {
            echo '<div class="update-nag notice is-dismissible" id="qtranxs-msg-new-lang"><p>' . sprintf(__('New language "%s" with two-letter code "%s" has been added to the configuration. You have to edit and finalize all its attributes in the form below. Read %sStartup Guide%s for more information.', 'qtranslate'), $language_name, $original_lang, '<a href="https://qtranslatexteam.wordpress.com/startup-guide/" target="_blank">', '</a>') . '</p></div>' . PHP_EOL;
        }
    }
    ?>
<input type="hidden" name="original_lang" value="<?php 
    echo $original_lang;
    ?>
" />
<div class="form-field form-field-code">
	<label for="language_code"><?php 
    _e('Language Code', 'qtranslate');
    ?>
<br/></label>
	<input name="language_code" id="language_ code" type="text" value="<?php 
    echo $language_code;
    ?>
" size="2" maxlength="2"/>
	<p class="qtranxs_notes"><?php 
    echo __('2-Letter <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm#2letter">ISO Language Code</a> for the Language you want to insert. (Example: en)', 'qtranslate') . '<br/>' . __('The language code is used in language tags and in URLs. It is case sensitive. Use of lower case for the language code is preferable, but not required. The code may be arbitrary chosen by site owner, although it is preferable to use already commonly accepted code if available. Once a language code is created and entries for this language are made, it is difficult to change it, please make a careful decision.', 'qtranslate');
    ?>
</p>
</div>
<div class="form-field form-field-flag">
	<label for="language_flag"><?php 
    _e('Flag', 'qtranslate');
    ?>
</label>
	<?php 
    $files = array();
    $flag_dir = trailingslashit(WP_CONTENT_DIR) . $q_config['flag_location'];
    if ($dir_handle = @opendir($flag_dir)) {
        while (false !== ($file = readdir($dir_handle))) {
            if (preg_match("/\\.(jpeg|jpg|gif|png|svg)\$/i", $file)) {
                $files[] = $file;
            }
        }
        sort($files);
    }
    if (sizeof($files) > 0) {
        ?>
	<select name="language_flag" id="language_flag" onchange="switch_flag(this.value);"  onclick="switch_flag(this.value);" onkeypress="switch_flag(this.value);">
	<?php 
        foreach ($files as $file) {
            ?>
		<option value="<?php 
            echo $file;
            ?>
" <?php 
            echo $language_flag == $file ? 'selected="selected"' : '';
            ?>
><?php 
            echo $file;
            ?>
</option>
	<?php 
        }
        ?>
	</select>
	<img src="" alt="<?php 
        _e('Flag', 'qtranslate');
        ?>
" id="preview_flag" style="vertical-align:middle; display:none"/>
	<?php 
    } else {
        _e('Incorrect Flag Image Path! Please correct it!', 'qtranslate');
    }
    ?>
	<p class="qtranxs_notes"><?php 
    _e('Choose the corresponding country flag for language. (Example: gb.png)', 'qtranslate');
    ?>
</p>
</div>
<script type="text/javascript">
//<![CDATA[
	function switch_flag(url) {
		document.getElementById('preview_flag').style.display = "inline";
		document.getElementById('preview_flag').src = "<?php 
    echo qtranxf_flag_location();
    ?>
" + url;
	}
	switch_flag(document.getElementById('language_flag').value);
//]]>
</script>
<div class="form-field form-field-name">
	<label for="language_name"><?php 
    _e('Name', 'qtranslate');
    echo ' ';
    _e('(in native alphabet)', 'qtranslate');
    ?>
<br/></label>
	<input name="language_name" id="language_name" type="text" value="<?php 
    echo $language_name;
    ?>
"/>
	<p class="qtranxs_notes"><?php 
    _e('The Name of the language, which will be displayed on the site. (Example: English)', 'qtranslate');
    ?>
</p>
</div>
<div class="form-field form-field-locale">
	<label for="language_locale"><?php 
    _e('Locale', 'qtranslate');
    ?>
<br/></label>
	<input name="language_locale" id="language_locale" type="text" value="<?php 
    echo $language_locale;
    ?>
" />
	<p class="qtranxs_notes">
	<?php 
    _e('PHP and Wordpress Locale for the language. (Example: en_US)', 'qtranslate');
    ?>
<br/>
	<?php 
    //_e('You will need to install the .mo file for this language.', 'qtranslate')
    printf(__('Make sure that the locale entered is listed in %sWordPress documentation%s, unless this is a new language, for which WordPress has not yet started translation. You will need to verify that translation .mo file for the locale chosen gets installed in WP_LANG_DIR folder "%s", otherwise the site will be displayed in English.', 'qtranslate'), '<a href="https://make.wordpress.org/polyglots/teams/" target="_blank">', '</a>', WP_LANG_DIR);
    ?>
	</p>
</div>
<?php 
    if ($original_lang) {
        ?>
<div class="form-field form-field-locale-html">
	<label for="language_locale_html"><?php 
        _e('Locale at front-end', 'qtranslate');
        ?>
<br/></label>
	<input name="language_locale_html" id="language_locale_html" type="text" value="<?php 
        echo $language_locale_html;
        ?>
" />
	<p class="qtranxs_notes">
	<?php 
        printf(__('Locale to be used in browser at front-end to set %s HTML attributes to specify alternative languages on a page. If left empty, then "%s" is used by default.', 'qtranslate'), '"hreflang"', __('Language Code', 'qtranslate'));
        ?>
<br/>
	</p>
</div>
<div class="form-field form-field-date-format">
	<label for="language_date_format"><?php 
        _e('Date Format', 'qtranslate');
        ?>
<br/></label>
	<input name="language_date_format" id="language_date_format" type="text" value="<?php 
        echo $language_date_format;
        ?>
"/>
	<p class="qtranxs_notes"><?php 
        if ($q_config['use_strftime'] == QTX_DATE_WP) {
            echo qtranxf_date_time_format_note('Date Format', empty($original_lang));
        } else {
            echo __('Depending on your Date / Time Conversion Mode, you can either enter a <a href="http://www.php.net/manual/function.strftime.php">strftime</a> (use %q for day suffix (st,nd,rd,th)) or <a href="http://www.php.net/manual/function.date.php">date</a> format. This field is optional. (Example: %A %B %e%q, %Y)', 'qtranslate') . '<br>' . qtranxf_obsolete_date_time_format_note();
        }
        ?>
</p>
</div>
<div class="form-field form-field-time-format">
	<label for="language_time_format"><?php 
        _e('Time Format', 'qtranslate');
        ?>
<br/></label>
	<input name="language_time_format" id="language_time_format" type="text" value="<?php 
        echo $language_time_format;
        ?>
"/>
	<p class="qtranxs_notes"><?php 
        if ($q_config['use_strftime'] == QTX_DATE_WP) {
            echo qtranxf_date_time_format_note('Time Format', empty($original_lang));
        } else {
            echo __('Depending on your Date / Time Conversion Mode, you can either enter a <a href="http://www.php.net/manual/function.strftime.php">strftime</a> or <a href="http://www.php.net/manual/function.date.php">date</a> format. This field is optional. (Example: %I:%M %p)', 'qtranslate') . '<br>' . qtranxf_obsolete_date_time_format_note();
        }
        ?>
</p>
</div>
<div class="form-field  form-field-nam">
	<label for="language_na_message"><?php 
        _e('Not Available Message', 'qtranslate');
        ?>
<br/></label>
	<input name="language_na_message" id="language_na_message" type="text" value="<?php 
        echo esc_html($language_na_message);
        ?>
"/>
	<p class="qtranxs_notes">
	<?php 
        _e('Message to display if post is not available in the requested language. (Example: Sorry, this entry is only available in %LANG:, : and %.)', 'qtranslate');
        ?>
<br/>
	<?php 
        _e('%LANG:&lt;normal_separator&gt;:&lt;last_separator&gt;% generates a list of languages separated by &lt;normal_separator&gt; except for the last one, where &lt;last_separator&gt; will be used instead.', 'qtranslate');
        echo ' ';
        printf(__('The language names substituted into the list of available languages are shown translated in the active language. The nominative form of language names is used as it is fetched from %s may not fit the grammar rules of your language. It is then advisable to include quotes in this message like this "%s". Alternatively you may modify "%s" files in folder "%s" with names that fit your grammar rules. Please, %scontact the development team%s, if you decide to modify "%s" files.', 'qtranslate'), '<a href="http://unicode.org/Public/cldr/latest" title="Unicode Common Locale Data Repository" target="_blank" tabindex="-1">CLDR</a>', 'Sorry, this entry is only available in "%LANG:", ":" and "%".', '.po', '<a href="https://github.com/qTranslate-Team/qtranslate-x/tree/master/lang/language-names" target="_blank" tabindex="-1">/lang/language-names/</a>', '<a href="https://qtranslatexteam.wordpress.com/contact-us/" target="_blank" tabindex="-1">', '</a>', '.po');
        ?>
	</p>
</div>
<?php 
    }
}