|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Mon Jan 24, 2011 3:52 pm Post subject: modifier.lower/upper fix for Smarty 3.0+ and iso-8859-9 |
|
|
Those, who need to use turkish charset, are well-aware of the annoying problem about "I"-> "ı", "İ"->"i" in every programming aspect (ie css capitalize, php mb_strtolower)
So far, with the change of modifiers in Smarty3.0, modifier.lower.php is replaced by modifiercompiler.lower.php, which invokes problem about converting "I"->"ı" and "İ"->"i" and as the variable you need to lowercase is stored as smarty variable, it is not so easy to fix it. - as far as in my case and in my knowledge.
Here's what I came up with.
1) rename your plugins/modifiercompiler.lower.php to plugins/bak_modifiercompiler.lower.php
2) create a new file plugins/modifier.lower.php (be sure to set encoding to UTF8 without BOM - in notepad++ you can do it easily by Edit)
3) Here's the code for modifier.lower.php
Code: |
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty lower modifier plugin
*
* Type: modifier
* Name: lower
* Purpose: convert string to lowercase
* @link http://smarty.php.net/manual/en/language.modifier.lower.php
* lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author n0aX <insomnis at gmail dot com>
* @param string
* @return string
*/
function smarty_modifier_lower($string)
{
if (function_exists('mb_strtolower'))
{
if (! function_exists('mb_str_replace'))
{
function mb_str_replace($needles, $replacements, $haystack)
{
$rep = (array) $replacements;
foreach ( (array) $needles as $key => $needle )
{
$replacement = $rep[$key];
$needle_len = mb_strlen($needle);
$replacement_len = mb_strlen($replacement);
$pos = mb_strpos($haystack, $needle, 0);
while($pos !== false)
{
$haystack = mb_substr($haystack, 0, $pos) . $replacement . mb_substr($haystack, $pos + $needle_len);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
}
}
return $haystack;
}
}
if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8')
{
$string = mb_str_replace(array('İ','I'), array('i','ı'), $string);
return mb_strtolower($string, 'UTF-8');
}
else
{
return strtolower($string);
}
}
else
{
return strtolower($string);
}
}
?>
|
4) Save your file.
5) Same can be applied to upper version.
Open for opinions and discussions.
See ya in cyberspace,
n0aX |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Jan 24, 2011 7:42 pm Post subject: |
|
|
I just looked up the characters in question:
I - U+0049 - latin capital letter i
i - U+0069 - latin small letter i
İ - U+0130 - latin capital letter i with dot above
ı - U+0131 - latin small letter dotless i
Lowercase according to unicode:
İ - U+0130 -> i - U+0069
I - U+0049 -> i - U+0069
So according to the unicode table both I and İ define i as their lower case representation.
If I were in your shoes, I'd probably rather build a new modifier to fix Turkish Characters than meddle with the standard compliant ones. So in my opinion your solution should look somewhat like {$var|lower_turkish|lower}. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|