Module: GetText::RGetText
- Extended by:
- GetText
- Defined in:
- lib/ramaze/contrib/gettext/po.rb
Overview
:nodoc:
Constant Summary collapse
- MAX_LINE_LEN =
70
Class Method Summary collapse
-
.generate(array) ⇒ Object
:nodoc:.
-
.generate_pot(ary) ⇒ Object
:nodoc:.
-
.generate_pot_header ⇒ Object
:nodoc:.
- .generate_translated_po(hash) ⇒ Object
Class Method Details
.generate(array) ⇒ Object
:nodoc:
98 99 100 101 102 |
# File 'lib/ramaze/contrib/gettext/po.rb', line 98 def generate(array) # :nodoc: str = '' str << generate_pot_header str << generate_pot(array) end |
.generate_pot(ary) ⇒ Object
:nodoc:
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ramaze/contrib/gettext/po.rb', line 51 def generate_pot(ary) # :nodoc: str = "" result = Array.new ary.each do |key| msgid = key.shift.dup curr_pos = MAX_LINE_LEN key.each do |e| if curr_pos + e.size > MAX_LINE_LEN str << "\n#:" curr_pos = 3 else curr_pos += (e.size + 1) end str << " " << e end msgid.gsub!(/"/, '\"') msgid.gsub!(/\r/, '') str << "\nmsgid \"" << msgid << "\"\n" str << "msgstr \"\"\n" end str end |
.generate_pot_header ⇒ Object
:nodoc:
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ramaze/contrib/gettext/po.rb', line 25 def generate_pot_header # :nodoc: time = Time.now.strftime("%Y-%m-%d %H:%M") off = Time.now.utc_offset sign = off <= 0 ? '-' : '+' time += sprintf('%s%02d%02d', sign, *(off.abs / 60).divmod(60)) <<EOS # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\\n" "POT-Creation-Date: #{time}\\n" "PO-Revision-Date: #{time}\\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" "Language-Team: LANGUAGE <[email protected]>\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" EOS end |
.generate_translated_po(hash) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ramaze/contrib/gettext/po.rb', line 75 def generate_translated_po(hash) str = generate_pot_header result = Array.new hash.keys.sort.each do |msgid| msgid = msgid.dup msgstr = hash[msgid] msgid.gsub!(/"/, '\"') msgid.gsub!(/\r/, '') if msgstr msgstr.gsub!(/"/, '\"') msgstr.gsub!(/\r/, '') end str << "\nmsgid \"" << msgid << "\"\n" str << "msgstr \"" << msgstr << "\"\n" end str end |