• 系统进行多语言支持转换


     
     
    makeLanguageConfig.php
    <?
    /*
    *@desc:生成语言包配置
    */
    $sourceFile = $argv[1];
    $configFile = $argv[2];
    if(empty($sourceFile) || empty($configFile)){
            help();
    }
     
    //清除原内容
    clearConfig($configFile);
    makeConfig($sourceFile,$configFile);
     
    function makeConfig($sourceFile,$configFile){
            $e = file_get_contents($sourceFile);
            $lines = explode("\n",$e);
            foreach($lines as $v){
                    $res = explode("\t",$v);
                    $arr[$res[0]]['other'] = $res[2]; //去重复
            }
            writeConfig("<?",$configFile);
            writeConfig('global $LANGUAGE_CONFIG;',$configFile);
            foreach($arr as $key => $v){
                    writeConfig('$LANGUAGE_CONFIG'."['{$key}'] = '{$v[other]}';",$configFile);
            }
    }
    function writeConfig($value,$configFile){
            file_put_contents($configFile,$value."\n",FILE_APPEND);
    }
     
     
    function clearConfig($configFile){
            file_put_contents("language.inc.php","");
    }
     
     
    function help(){
            echo "
            =========================================================
            生成语言包配置请按以下格式运行
            php  makeLanguageConfig.php 语言包文件 语言包配置
            =========================================================
            ";
            die();
     
     
    getChineseWord.php
    <?php
    /**
    *@desc:获取文件夹下所有的中文字符
    */
     
    $dir = $argv [1];
     
    if (empty ( $dir )) {
            help ();
    }
     
    /**
    * 遍历所有目录
    */
    $it = new RecursiveDirectoryIterator ( $dir );
    foreach ( new RecursiveIteratorIterator ( $it ) as $file ) {
            if (strpos ( $file, "svn" )) {
                    continue;
            }
            getChineseWord ( $file );
    }
     
    /**
    * 获取文件中的中文字符
    *
     * @param unknown_type $file           
    */
    function getChineseWord($file) {
            $x = file_get_contents ( $file );
            if (preg_match_all ( "/([\x{4e00}-\x{9fa5}\x{fe30}-\x{ffa0}]*)/u", $x, $match )) {
                    foreach ( $match [0] as $k => $v ) {
                            if (! empty ( $v )) {
                                    $wordList [$v] = $v; // 去重
                            }
                    }
                    if(!empty($wordList)){
                    foreach($wordList as $v){
                            echo $v."\n";
                    }
                    }
            }
    }
    function help() {
            echo " 
            ==============================================
            请按以下参数运行
            php getChineseWord.php 文件夹 > 生成的文件名
            ==============================================
    ";
            die ();
    }
     
     
    <?php
    /**
    *@desc: 替换多语言标签
    */
     
    $dir = $argv [1];
     
    if (empty ( $dir )) {
            help ();
    }
     
    /**
    * 遍历所有目录
    */
    $it = new RecursiveDirectoryIterator ( $dir );
    foreach ( new RecursiveIteratorIterator ( $it ) as $file ) {
            //  $link = $file->getPath(); 
            //  $name = $file->getFileName(); 
            //  $fileName = $link."/".$name;
            if (strpos ( $file, "svn" )) {
                    continue;
            }
            translater ( $file );
    }
     
    /**
    * 获取文件中的中文字符
    *
     * @param unknown_type $file           
    */
    function translater($file) {
            $arr = explode(".",$file);
            $fileType = end($arr);
            doReplace($file,$fileType);
    }
    function doReplace($file,$type){
            require "./language.inc.php";
            global $LANGUAGE_CONFIG;
            $newFileCnt = "";
            $cfile = file($file);
            foreach($cfile as &$line){
                    if (preg_match_all ( "/([\x{4e00}-\x{9fa5}\x{fe30}-\x{ffa0}]*)/u", $line, $match )) {
                            foreach ( $match[0] as $k => $v ) {
                                    if (! empty ( $v )) {
                                            $oldValue[] = $v;
                                            if($type == "php" ){
                                                    $newString = $LANGUAGE_CONFIG[$v];
                                            }else if($type == "tpl" || $type=="html"){
                                                    $newString = "<{lang l='{$v}'}>";
                                            }
                                            $newValue[] = $newString;
                                    }
                            }
                            if(is_array($newValue) && !empty($newValue)){
                                    $string = @str_replace($oldValue,$newValue,$line);
                                    $newFileCnt .= $string;
                            }else{
                                    $newFileCnt .= $line;
                            }
                    }
            }
    //      echo $newFileCnt;
            file_put_contents($file,$newFileCnt);
    }
     
    function help() {
            echo " 
                    ==============================================
                    请按以下参数运行
                    php translater.php 文件夹 > 生成的文件名
                    ==============================================
                    ";
            die ();
    }
     




  • 相关阅读:
    java性能优化之HashMap,LinkedHashMap,TreeMap读取大量数据效率的比较
    jdk8 stream实现sql单表select a,b,sum(),avg(),max() from group by a,b order by a,b limit M offset N及其性能
    postgresql cstore_fdw性能测试
    Oracle JDBC prefetch: how to avoid running out of RAM
    mysql-创建用户报错ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'localhost'
    kafka外部访问设置
    mysql 排序长度限制之max_length_for_sort_data以及mysql两种排序算法
    mybatis三个执行器的差别
    Dubbo的集群容错与负载均衡策略及自定义(一致性哈希路由的缺点及自定义)
    mysql中包含长字段索引的优化
  • 原文地址:https://www.cnblogs.com/firmy/p/2816983.html
Copyright © 2020-2023  润新知