V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
starit
V2EX  ›  编程

请问有没有方法能自动替换代码里的 language key?

  •  
  •   starit · Aug 10, 2015 · 3068 views
    This topic created in 3920 days ago, the information mentioned may be changed or developed.

    最近碰上一个需求,需要对系统里的本地化系统进行改造

    比如,原来的代码里语言的翻译都是写成
    $this->_t('你好,世界');
    然后在一个翻译文件如en.json里写
    {"你好,世界":"Hello,world"}

    现在需要将其改成language key,
    $this->_t('lang_global_hello_world');
    然后在一个翻译文件如en.json里写
    {"lang_global_hello_world":"Hello,world"}
    在zh.json里写
    {"lang_global_hello_world:"你好,世界"}

    代码里有3K多条翻译,如果手动一条条改会死人的。。所以想请教一下有什么办法能快速修改吗?

    我查过的一点资料:我查到有gettext里的有能通过源代码文件导出对应的翻译文字的方法,但不会对其进行修改,我想知道有没有工具扫描文件时顺带对其进行修改??

    1 replies    2015-08-11 08:17:34 +08:00
    breeswish
        1
    breeswish  
       Aug 11, 2015   ❤️ 1
    写份代码转换一下大概也就几分钟就写好了……

    1/ 扫描所有代码文件,这个用第三方库一般叫 glob.. 看不同语言..
    2/ 扫描语言文件..感觉这个自己处理一下也行格式很简单..
    3/ 读取代码,全文替换,保存代码
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2771 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:13 · PVG 16:13 · LAX 01:13 · JFK 04:13
    ♥ Do have faith in what you're doing.