Add grunt task for compiling gettext PO files for Chromium Extensions.

This commit is contained in:
FelisCatus 2015-02-15 20:55:06 +08:00
parent f68b0ae3d3
commit cc526b819f
11 changed files with 75 additions and 19 deletions

View File

@ -1027,8 +1027,8 @@ msgstr "SwitchyOmega:: $PROFILE$"
msgid "browserAction_titleWithResult"
msgstr ""
"SwitchyOmega:: $PROFILE$\n"
"$DETAILS$"
"SwitchyOmega:: $1:PROFILE$\n"
"$3:DETAILS$"
msgid "browserAction_titleNewerOptions"
msgstr ""

View File

@ -22,7 +22,7 @@ msgid "manifest_app_description"
msgstr "Manage and switch between multiple proxies quickly & easily."
msgid "manifest_icon_default_title"
msgstr "Loading..."
msgstr "Loading"
msgid "upgrade_profile_auto"
msgstr "Auto Switch"
@ -44,7 +44,7 @@ msgstr ""
"code> are specially treated only in Host wildcard conditions.<br>Example: <"
"code>*.example.com</code> will match www.example.com <b>AND example.com as "
"well.</b><br>To match subdomains <b>only</b>, use <b>two</b> asterisks like <"
"code>**.example.com</code>"
"code>**.example.com</code>."
msgid "condition_HostRegexCondition"
msgstr "Host regex"
@ -190,7 +190,7 @@ msgid "options_tab_importExport"
msgstr "Import/Export"
msgid "options_newProfile"
msgstr "New profile..."
msgstr "New profile"
msgid "options_apply"
msgstr "Apply changes"
@ -491,7 +491,7 @@ msgid "options_bypassListHelp"
msgstr "Servers for which you do not want to use any proxy: (One server on each line.)"
msgid "options_bypassListHelpLinkText"
msgstr "(Wildcards and more available...)"
msgstr "(Wildcards and more available)"
msgid "options_group_pacUrl"
msgstr "PAC URL"
@ -1016,8 +1016,8 @@ msgstr "SwitchyOmega:: $PROFILE$"
msgid "browserAction_titleWithResult"
msgstr ""
"SwitchyOmega:: $PROFILE$\n"
"$DETAILS$"
"SwitchyOmega:: $1:PROFILE$\n"
"$3:DETAILS$"
msgid "browserAction_titleNewerOptions"
msgstr "ERROR: A newer version of SwitchOmega is required to load the stored options."

View File

@ -1032,8 +1032,8 @@ msgstr "SwitchyOmega:: $PROFILE$"
msgid "browserAction_titleWithResult"
msgstr ""
"SwitchyOmega:: $PROFILE$\n"
"$DETAILS$"
"SwitchyOmega:: $1:PROFILE$\n"
"$3:DETAILS$"
msgid "browserAction_titleNewerOptions"
msgstr ""

View File

@ -897,8 +897,8 @@ msgstr "SwitchyOmega:: $PROFILE$"
msgid "browserAction_titleWithResult"
msgstr ""
"SwitchyOmega:: $PROFILE$\n"
"$DETAILS$"
"SwitchyOmega:: $1:PROFILE$\n"
"$3:DETAILS$"
msgid "browserAction_titleNewerOptions"
msgstr "错误需要新版本的SwitchyOmega才能加载当前选项。"

View File

@ -897,8 +897,8 @@ msgstr "SwitchyOmega:: $PROFILE$"
msgid "browserAction_titleWithResult"
msgstr ""
"SwitchyOmega:: $PROFILE$\n"
"$DETAILS$"
"SwitchyOmega:: $1:PROFILE$\n"
"$3:DETAILS$"
msgid "browserAction_titleNewerOptions"
msgstr "錯誤需要新版本的SwitchyOmega才能載入當前選項。"

View File

@ -1 +1,3 @@
module.exports = require('load-grunt-config')
module.exports = (grunt) ->
require('load-grunt-config')(grunt)
require('./grunt-po2crx')(grunt)

View File

@ -0,0 +1,41 @@
module.exports = (grunt) ->
taskDesc = 'Convert gettext PO files to Chromium Extension messages format.'
# coffeelint: disable=missing_fat_arrows
grunt.registerMultiTask 'po2crx', taskDesc, ->
for f in this.files
result = {}
for src in f.src
json = require('po2json').parseFileSync(src)
for own key, value of json when key
message = value[1]
refs = []
matchCount = 0
message = message.replace /\$(\d+:)?(\w+)\$/g, (_, order, ref) ->
matchCount++
if order
order = parseInt(order)
else
order = matchCount
### TODO(catus): Shall we enable this warning?
if matchCount > 1
grunt.log.writeln("In this message: #{key}=#{message}")
grunt.log.writeln(
'Order not specified for two or more refs in same message.')
###
refs[order] = ref
return '$' + ref + '$'
if not matchCount
placeholders = undefined
else
placeholders = {}
for i in [0...refs.length]
placeholder = refs[i] ? ('_unused_' + i)
placeholders[placeholder] = {content: '$' + i}
result[key] =
message: message
placeholders: placeholders
grunt.file.write(f.dest, JSON.stringify(result))
grunt.log.writeln("File \"#{f.dest}\" created.")
# coffeelint: enable=missing_fat_arrows

View File

@ -4,6 +4,7 @@ module.exports =
'browserify'
'coffee'
'copy'
'po2crx'
]
test: ['mochaTest']
release: ['default', 'compress']

View File

@ -0,0 +1,11 @@
module.exports =
locales:
files:
'build/_locales/en/messages.json':
'../omega-locales/en_US/LC_MESSAGES/omega-web.po'
'build/_locales/zh/messages.json':
'../omega-locales/zh_CN/LC_MESSAGES/omega-web.po'
'build/_locales/zh_CN/messages.json':
'../omega-locales/zh_CN/LC_MESSAGES/omega-web.po'
'build/_locales/zh_TW/messages.json':
'../omega-locales/zh_TW/LC_MESSAGES/omega-web.po'

View File

@ -5,12 +5,12 @@ module.exports =
files:
'grunt/*'
tasks: ['coffeelint:tasks', 'default']
po2crx_locales:
files: ['../omega-locales/**/*']
tasks: ['po2crx:locales']
copy_web:
files: ['node_modules/omega-web/build/**/*']
tasks: ['copy:web']
copy_i18n:
files: ['../omega-i18n/**/*']
tasks: ['copy:i18n', 'copy:i18n_zh']
copy_target:
files: ['node_modules/omega-target/omega_target.min.js']
tasks: ['copy:target']

View File

@ -16,7 +16,8 @@
"grunt-contrib-watch": "^0.6.1",
"grunt-mocha-test": "~0.11.0",
"load-grunt-config": "^0.13.1",
"minifyify": "^4.1.1"
"minifyify": "^4.1.1",
"po2json": "^0.3.2"
},
"dependencies": {
"omega-target": "../omega-target",