PHP实现的JavaScript字符串提取与翻译辅助工具

JavaScript

Overview A PHP script which extracts strings from Javascript code and merges with an existing .po file. Then you can translate strings using Poedit. Includes a small script that converts .po files into JSON so you can include it as an external file in your web application and invoke a function that translates. The script is smart enough to extract strings excluding regular expressions and comments. Usage Open Poedit, go to preferences and add a new parser. The command must point to the script "jsgettext.php". Eg: php /home/www/projects/jsgettext/jsgettext.php -o %o -k "%K" %F Create a new catalog and set the base folder which contains the Javascript files you want to parse. Proceed to update from source, translate and save file. Exec the following command (check the command location and update path): /*Options:-i input file name-o output file name-k javascript global var name which

详细介绍

资源简介:

  • 本源码是一套用PHP开发的实用工具,主要用于从JavaScript代码中自动提取可翻译字符串,并与现有的.po文件进行合并。通过这种方式,开发者可以方便地利用Poedit等翻译软件对前端脚本中的文本进行国际化处理。

核心功能:

  • 自动扫描指定目录下的JavaScript文件,智能识别并提取所有待翻译的字符串内容。
  • 在提取过程中,脚本能够有效排除正则表达式和注释内容,避免误将非文本部分纳入翻译范围,提高准确性。
  • 支持与现有.po语言包文件合并,实现增量更新,无需重复劳动。
  • 内置转换脚本,可将.po格式文件转为JSON格式,便于直接作为外部资源集成到Web应用中,并通过调用相关函数实现动态多语言切换。

使用场景与适用人群:

  • 适用于需要对前端JavaScript界面进行多语言国际化的网站和Web应用开发项目。
  • 特别适合使用Poedit等主流翻译工具管理语言包、希望简化前后端协作流程的开发团队和个人程序员。
  • 对于频繁更新或维护多语种界面的项目,该工具可显著提升工作效率和一致性。

操作说明简述:

  • 用户只需在Poedit中添加自定义解析器,将命令指向jsgettext.php脚本,即可自动完成字符串提取和.po文件生成。
  • .po文件经编辑后,可利用附带的小脚本转为JSON格式,方便Web端直接加载和调用,实现实时多语言切换功能。

特点总结:

  • 无需手动查找或复制粘贴文本,大幅减少出错概率。
  • 兼容主流国际化工作流,易于集成进现有开发体系。
  • 轻量级、开源、易于二次开发和扩展。
📦

确认下载

资源名称

消耗积分