1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-08 20:58:17 +03:00
one/share/scons/po2json.rb
Hector Sanjuan d84ce02d44 Feature #1302: Update Self-Service to be IE compatible
* Javascript adaptation for IE >= 7
 * Updated crypto-js library. Added base64 enconding library for IE as browser does not support btoa()
 * Update langauge compilation plugin to produce IE >= 7 compatible translation files.
 * Added login warning for IE
(cherry picked from commit 1e9cdff570b9eb9118a94ae47ab196663d9820b0)
2012-07-19 01:59:07 +02:00

66 lines
2.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
if !ARGV[0]
puts "Usage ./po2json.rb <file.po> > <output.js>"
exit 1
end
po_file = File.open(ARGV[0])
lang = File.basename(ARGV[0]).split('.')[0]
datatable_lang = lang.split("_")[0]
puts "lang=\"#{lang}\""
puts "datatable_lang=\"#{datatable_lang}_datatable.txt\""
puts "locale={"
msgid = nil
tr_lines = []
po_file.each do |line|
if msgid
msgstr = line.sub("msgstr ", "").chomp
tr_lines << " #{msgid}:#{msgstr}"
msgid = nil
next
end
if line.include?("msgid")
msgid = line.sub("msgid ", "").chomp
if msgid.length == 0 || msgid.slice(0,1) == '#'
msgid = nil
end
end
end
tr_lines[0..-2].each do |line|
puts line+','
end
# last line must not have an ending , for IE7 JS compatibility
puts tr_lines[-1]
puts "}"