<?php
$lang['comment_form_0'] = '';
$lang['comment_form_1'] = '';
$lang['comment_form_2'] = '';
$lang['comment_form_3'] = '';
$lang['comment_form_4'] = '';
$lang['comment_form_5'] = '';
?>
Copy Source | Copy HTML<br/> <?php <br/> /** <br/> * get localized text by key in multi variant cases. <br/> * Attention: Lang ID is first-level domain for country but not ISo lang identificator! <br/> * <br/> * @param string $key - base part of key <br/> * @param int $n - number of items <br/> ( special case == 0 -- it means that text will be fetched simply by $key) <br/> * @param string|null - lang ID which will be used for plural form check <br/> * <br/> * @return string - localized text <br/> */ <br/> function get_lang( $key , $n = null, $lang_id = null ) {<br/> <br/> global $lang ;<br/> if ( null === $n ) {<br/> return $lang [ $key ];<br/> }<br/> <br/> $key_postfix = '_form_' ;<br/> <br/> switch ( $lang_id ) {<br/> <br/> case 'ar' : // arabic, nplurals=6 <br/> $s = $key_postfix .( ( $n == 0 ) ? '0' : ( ( $n == 1 ) ? 1 : ( ( $n == 2 ) ? 2 : ( ( ( $n % 100 >= 3 ) && ( $n % 100 <= 10 ) ) ? '3' : ( ( ( $n % 100 >= 11 ) && ( $n % 100 <= 99 ) ) ? '4' : '5' ) ) ) ) );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'cz' : // czech, nplurals=3 <br/> $s = $key_postfix .( ( $n == 1 ) ? '0' : ( $n >= 2 && $n <= 4 ) ? '1' : '2' );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'de' : // german <br/> case 'bg' : // bulgarian <br/> case 'gr' : // greek <br/> case 'en' : // english <br/> case 'es' : // espanol <br/> case 'ee' : // estonian <br/> case 'il' : // hebrew <br/> case 'it' : // italian <br/> case 'mn' : // mongolian <br/> case 'nl' : // dutch <br/> case 'sq' : // albainian <br/> case 'my' : // malay <br/> // nplurals=2; <br/> $s = $key_postfix .( ( $n != 1 ) ? '0' : '1' );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'pl' : // polskiy, nplurals=3 <br/> $s = $key_postfix .( ( $n == 1 ) ? '0' : ( ( $n % 10 >= 2 ) && ( $n % 10 <= 4 ) && ( $n % 100 < 10 || $n % 100 >= 20 ) ) ? '1' : '2' );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'ru' : // russian, nplurals=3 <br/> $s = $key_postfix .( (( $n % 10 == 1 ) && ( $n % 100 != 11 )) ? '0' : (( ( $n % 10 >= 2 ) && ( $n % 10 <= 4 ) && ( $n % 100 < 10 || $n % 100 >= 20 )) ? '1' : '2' ) );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'sk' : // Slovak, nplurals=3 <br/> $s = $key_postfix .( ( $n == 1 ) ? '1' : ( ( $n >= 2 && $n <= 4 ) ? '2' : '0' ) );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'fa' : // farsi <br/> case 'ja' : // japan <br/> case 'tr' : // turkish <br/> case 'vn' : // vietnamese <br/> case 'cn' : // chinese + <br/> case 'tw' : // tradional Chinese (?) <br/> case 'kz' : // Kazakh <br/> // nplurals=1 <br/> $s = $key_postfix . '0' ;<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'ua' : // ukrainian, nplurals=3 <br/> $s = $key_postfix .( ( $n % 10 == 1 && $n % 100 != 11 ) ? '0' : ( $n % 10 >= 2 && $n % 10 <= 4 && ( $n % 100 < 10 || $n % 100 >= 20 ) ) ? '1' : '2' );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'lt' : // Lithuanian, nplurals=3 <br/> $s = $key_postfix .( ( $n % 10 == 1 && $n % 100 != 11 ) ? '0' : ( $n % 10 >= 2 && ( $n % 100 < 10 || $n % 100 >= 20 ) ) ? '1' : '2' );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> <br/> case 'fr' : // french, nplurals=2 <br/> $s = $key_postfix .( $n > 1 ? '0' : '1' );<br/> $localized = $lang [ $key . $s ];<br/> break ;<br/> }<br/> <br/> return $localized ;<br/>}<br/> ?> <br/>
Source: https://habr.com/ru/post/56864/
All Articles