File: installer.rb

package info (click to toggle)
mkvtoolnix 92.0-1
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 58,620 kB
  • sloc: cpp: 216,810; ruby: 11,403; xml: 8,058; ansic: 6,885; sh: 4,884; python: 1,041; perl: 191; makefile: 113; awk: 16; javascript: 4
file content (64 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module Mtx::Installer
  def self.read_translation_file file_name
    # Local Variables:
    # mode: nsi
    # coding: windows-1252-unix
    # End:

    all_lines    = IO.readlines(file_name, $/, :encoding => "ASCII-8BIT").map(&:chomp)
    language     = all_lines.first  { |line| %r{^!define \s+ LANG \s+}x.match line }
    emacs        = all_lines.select { |line| %r{^\# \s+ (Local \s+ Variables|mode|coding|End) :}ix.match line }
    translations = Hash[
      *all_lines.
      map { |line| %r{^!insertmacro \s+ LANG_STRING \s+ ([^\s]+) \s+ "(.+)" $}x.match(line) ? [ $1, $2 ] : nil }.
      reject(&:nil?).
      flatten
    ]

    return {
      :language     => language,
      :translations => translations,
      :emacs        => emacs,
    }
  end

  def self.update_one_translation_file file_name, english
    puts_qaction "nsh_update", :target => file_name

    language        = self.read_translation_file file_name
    translation_lines = []
    prefix            = "!insertmacro LANG_STRING "

    english[:translations].keys.sort.each do |name|
      english_text    = english[:translations][name]
      language_text = language[:translations][name].to_s

      if language_text.empty? || (language_text == english_text)
        translation_lines += [
          "# The next entry needs translations:",
          "#{prefix}#{name} \"#{english_text}\""
        ]
      else
        translation_lines << "#{prefix}#{name} \"#{language_text}\""
      end
    end

    all_lines = [ language[:language] ] +
      [ "" ] +
      translation_lines +
      [ "" ] +
      language[:emacs]

    IO.write(file_name, all_lines.join("\n") + "\n")
  end

  def self.update_all_translation_files
    english = self.read_translation_file "packaging/windows/installer/translations/English.nsh"

    FileList["packaging/windows/installer/translations/*.nsh"].to_a.sort.each do |file_name|
      next if %r{/English\.nsh$}.match file_name
      # next unless %r{German}.match file_name
      self.update_one_translation_file file_name, english
    end
  end
end