Welcome to mirror list, hosted at ThFree Co, Russian Federation.

flash.rb « formatters « twine « lib - github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5a1855b94a986ea4b74744cbed66b73cede5cc1d (plain)
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
65
66
67
68
69
70
71
72
73
74
75
module Twine
  module Formatters
    class Flash < Abstract
      include Twine::Placeholders

      def format_name
        'flash'
      end

      def extension
        '.properties'
      end

      def can_handle_directory?(path)
        return false
      end

      def default_file_name
        return 'resources.properties'
      end

      def determine_language_given_path(path)
        return
      end

      def set_translation_for_key(key, lang, value)
        value = convert_placeholders_from_flash_to_twine(value)
        super(key, lang, value)
      end

      def read(io, lang)
        last_comment = nil
        while line = io.gets
          match = /((?:[^"\\]|\\.)+)\s*=\s*((?:[^"\\]|\\.)*)/.match(line)
          if match
            key = match[1]
            value = match[2].strip

            set_translation_for_key(key, lang, value)
            set_comment_for_key(key, last_comment) if last_comment
          end
          
          match = /# *(.*)/.match(line)
          last_comment = match ? match[1] : nil
        end
      end

      def format_sections(twine_file, lang)
        super + "\n"
      end

      def format_header(lang)
        "## Flash Strings File\n## Generated by Twine #{Twine::VERSION}\n## Language: #{lang}"
      end

      def format_section_header(section)
        "## #{section.name} ##\n"
      end

      def format_comment(definition, lang)
        "# #{definition.comment}\n" if definition.comment
      end

      def key_value_pattern
        "%{key}=%{value}"
      end

      def format_value(value)
        convert_placeholders_from_twine_to_flash(value)
      end
    end
  end
end

Twine::Formatters.formatters << Twine::Formatters::Flash.new