2011-12-02 20:55:26 +04:00
#!/usr/bin/env ruby
2011-12-12 18:19:45 +04:00
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------- #
2013-01-24 19:03:57 +04:00
# Copyright 2002-2013, OpenNebula Project Leads (OpenNebula.org) #
2011-12-12 18:19:45 +04:00
# #
# 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. #
#--------------------------------------------------------------------------- #
2011-12-02 20:55:26 +04:00
2012-05-24 16:43:43 +04:00
if RUBY_VERSION =~ / 1.9 /
Encoding . default_external = Encoding :: UTF_8
Encoding . default_internal = Encoding :: UTF_8
end
2012-05-21 16:40:42 +04:00
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 ]
2011-12-02 20:55:26 +04:00
2012-05-21 16:40:42 +04:00
puts " lang= \" #{ lang } \" "
puts " datatable_lang= \" #{ datatable_lang } _datatable.txt \" "
2011-12-02 20:55:26 +04:00
puts " locale={ "
2012-05-21 16:40:42 +04:00
msgid = nil
2012-07-18 15:03:27 +04:00
tr_lines = [ ]
2012-05-21 16:40:42 +04:00
po_file . each do | line |
if msgid
msgstr = line . sub ( " msgstr " , " " ) . chomp
2012-07-18 15:03:27 +04:00
tr_lines << " #{ msgid } : #{ msgstr } "
2012-05-21 16:40:42 +04:00
msgid = nil
next
end
2012-05-24 16:43:43 +04:00
2012-05-21 16:40:42 +04:00
if line . include? ( " msgid " )
msgid = line . sub ( " msgid " , " " ) . chomp
2012-05-24 16:43:43 +04:00
2012-05-21 17:34:40 +04:00
if msgid . length == 0 || msgid . slice ( 0 , 1 ) == '#'
2012-05-21 16:40:42 +04:00
msgid = nil
end
end
2012-05-24 16:43:43 +04:00
2011-12-02 20:55:26 +04:00
end
2012-07-18 15:03:27 +04:00
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 ]
2012-05-21 16:40:42 +04:00
puts " } "