PEAK XOOPS - Re: 日本語サイトでのロシア語表示 in englishin japanese

Re: 日本語サイトでのロシア語表示

List posts in the topic

question Re: 日本語サイトでのロシア語表示

msg# 1.1.2.1.1.1
depth:
5
Previous post - Next post | Parent - No child | Posted on 2005/12/12 18:20
GIJOE  先任軍曹   Posts: 4110
すみませんが、数分で出来ると判っている案件では依頼を受ける気にはなれません。

というわけで、動くんじゃないかな、という程度のコードを書いておきます。
言語ファイルadmin.php の WINDOWS-1251 は全部大文字で。

<?php
if (function_exists('mb_convert_encoding') && ! class_exists( 'XhldRendererLocal' ) ) {
	class XhldRendererLocal extends XhldRenderer
	{
		function XhldRendererLocal( &$headline , $mydirname='xhld0' )
		{
			parent::XhldRenderer( $headline , $mydirname ) ;
			if( ! preg_match( '/(EUC-JP|UTF-8|SJIS)/i' , mb_internal_encoding() ) ) {
				mb_internal_encoding( 'EUC-JP' ) ;
			}
		}

		function convertFromUtf8(&$value, $key)
		{
			if( ! is_string( $value ) ) return ;
			if( stristr( _CHARSET , 'iso-8859-1' ) ) {
				$value = utf8_decode( $value ) ;
			} else if( $this->_hl->getVar('headline_encoding') == 'iso-8859-1' && ! $this->_hl->getVar('headline_allowhtml') ) {
				$value = htmlentities( utf8_decode( $value ) ) ;
			} else if( $this->_hl->getVar('headline_encoding') == 'WINDOWS-1251' && ! $this->_hl->getVar('headline_allowhtml') ) {
				$value = iconv( "UTF-8" , "WINDOWS-1251" , $value ) ;
			} else {
				$value = mb_convert_encoding( $value , mb_internal_encoding() , 'UTF-8' ) ;
			}
		}

		function &convertToUtf8(&$xmlfile)
		{
			$encoding = $this->_hl->getVar('headline_encoding') ;

			// auto detection
			if( empty( $encoding ) ) {
				$top_of_xml = substr( $xmlfile , 0 , 255 ) ;
				preg_match( "/^<\?xml .* encoding=['\"]?([0-9a-z_-]+)/i", $top_of_xml , $regs ) ;
				if( empty( $regs ) ) {
					$encoding = 'utf-8' ;
				} else if( stristr( $regs[1] , 'JIS' ) ) {
					$encoding = 'shift_jis' ;
				} else if( stristr( $regs[1] , 'euc' ) ) {
					$encoding = 'euc-jp' ;
				} else if( stristr( $regs[1] , 'utf-8' ) ) {
					$encoding = 'utf-8' ;
				} else {
					$encoding = strtolower( $regs[1] ) ;
				}
				$this->_hl->setVar( 'headline_encoding' , $encoding ) ;
				$headline_handler =& xoops_getmodulehandler('headline', $this->_mydirname);
				$headline_handler->insert($this->_hl);
			}

			switch( strtolower( $encoding ) ) {
				case 'iso-8859-1' :
					$xmlfile = utf8_encode( $xmlfile ) ;
					break ;
				case 'shift_jis' :
					$xmlfile = str_replace( chr( 0 ) , '' , mb_convert_encoding( $xmlfile , "UTF-8" , "Shift_JIS" ) ) ;
					break ;
				case 'euc-jp' :
					$xmlfile = str_replace( chr( 0 ) , '' , mb_convert_encoding( $xmlfile , "UTF-8" , "EUC-JP" ) ) ;
					break ;
				case 'windows-1251' :
					$xmlfile = iconv( "WINDOWS-1251" , "UTF-8" , $xmlfile ) ;
					break ;
				case 'koi8-r'  :
					$xmlfile = iconv( "KOI8-R" , "UTF-8" , $xmlfile ) ;
					break ;
				case 'koi8-u'  :
					$xmlfile = iconv( "KOI8-U" , "UTF-8" , $xmlfile ) ;
					break ;
				case 'koi8-ru'  :
					$xmlfile = iconv( "KOI8-RU" , "UTF-8" , $xmlfile ) ;
					break ;
				case 'utf-8' :
				default :
					break ;
			}

			return $xmlfile;
		}
	}
}
?>
Votes:9 Average:10.00

Posts tree

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!