translatomatic 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.translatomatic/config.yml +18 -0
  3. data/.travis.yml +33 -33
  4. data/Gemfile +6 -4
  5. data/README.de.md +53 -18
  6. data/README.es.md +55 -20
  7. data/README.fr.md +54 -19
  8. data/README.it.md +58 -23
  9. data/README.ja.md +54 -19
  10. data/README.ko.md +58 -23
  11. data/README.md +167 -141
  12. data/README.ms.md +51 -16
  13. data/README.pt.md +58 -23
  14. data/README.ru.md +53 -18
  15. data/README.sv.md +53 -18
  16. data/README.zh.md +53 -18
  17. data/bin/translatomatic +6 -6
  18. data/bin/travis +24 -26
  19. data/config/locales/translatomatic/de.yml +22 -11
  20. data/config/locales/translatomatic/en.yml +21 -12
  21. data/config/locales/translatomatic/es.yml +22 -11
  22. data/config/locales/translatomatic/fr.yml +22 -12
  23. data/config/locales/translatomatic/it.yml +22 -11
  24. data/config/locales/translatomatic/ja.yml +22 -11
  25. data/config/locales/translatomatic/ko.yml +22 -11
  26. data/config/locales/translatomatic/ms.yml +22 -11
  27. data/config/locales/translatomatic/pt.yml +22 -11
  28. data/config/locales/translatomatic/ru.yml +22 -11
  29. data/config/locales/translatomatic/sv.yml +22 -11
  30. data/config/locales/translatomatic/zh.yml +22 -11
  31. data/db/migrate/201712170000_initial.rb +25 -25
  32. data/lib/translatomatic/cli/base.rb +81 -73
  33. data/lib/translatomatic/cli/config.rb +110 -81
  34. data/lib/translatomatic/cli/main.rb +85 -72
  35. data/lib/translatomatic/cli/translate.rb +141 -106
  36. data/lib/translatomatic/cli.rb +8 -8
  37. data/lib/translatomatic/config.rb +302 -155
  38. data/lib/translatomatic/converter.rb +28 -260
  39. data/lib/translatomatic/database.rb +134 -134
  40. data/lib/translatomatic/define_options.rb +22 -0
  41. data/lib/translatomatic/escaped_unicode.rb +0 -0
  42. data/lib/translatomatic/extractor/base.rb +16 -16
  43. data/lib/translatomatic/extractor/ruby.rb +6 -6
  44. data/lib/translatomatic/extractor.rb +5 -5
  45. data/lib/translatomatic/file_translator.rb +269 -0
  46. data/lib/translatomatic/http_request.rb +162 -162
  47. data/lib/translatomatic/locale.rb +76 -76
  48. data/lib/translatomatic/logger.rb +23 -23
  49. data/lib/translatomatic/model/locale.rb +25 -25
  50. data/lib/translatomatic/model/text.rb +19 -19
  51. data/lib/translatomatic/model.rb +1 -1
  52. data/lib/translatomatic/option.rb +37 -41
  53. data/lib/translatomatic/progress_updater.rb +13 -13
  54. data/lib/translatomatic/resource_file/base.rb +269 -192
  55. data/lib/translatomatic/resource_file/csv.rb +37 -0
  56. data/lib/translatomatic/resource_file/html.rb +54 -47
  57. data/lib/translatomatic/resource_file/markdown.rb +50 -55
  58. data/lib/translatomatic/resource_file/plist.rb +153 -19
  59. data/lib/translatomatic/resource_file/po.rb +107 -0
  60. data/lib/translatomatic/resource_file/properties.rb +91 -90
  61. data/lib/translatomatic/resource_file/resw.rb +50 -30
  62. data/lib/translatomatic/resource_file/subtitle.rb +75 -0
  63. data/lib/translatomatic/resource_file/text.rb +24 -30
  64. data/lib/translatomatic/resource_file/xcode_strings.rb +75 -80
  65. data/lib/translatomatic/resource_file/xml.rb +98 -91
  66. data/lib/translatomatic/resource_file/yaml.rb +94 -116
  67. data/lib/translatomatic/resource_file.rb +87 -78
  68. data/lib/translatomatic/string.rb +188 -188
  69. data/lib/translatomatic/tmx/document.rb +99 -99
  70. data/lib/translatomatic/translation_result.rb +63 -63
  71. data/lib/translatomatic/{converter_stats.rb → translation_stats.rb} +17 -17
  72. data/lib/translatomatic/translator/base.rb +1 -1
  73. data/lib/translatomatic/translator/google.rb +2 -0
  74. data/lib/translatomatic/translator.rb +10 -2
  75. data/lib/translatomatic/util.rb +45 -45
  76. data/lib/translatomatic/version.rb +7 -7
  77. data/lib/translatomatic.rb +52 -49
  78. data/translatomatic.gemspec +3 -2
  79. metadata +25 -5
@@ -1,81 +1,110 @@
1
- module Translatomatic::CLI
2
- # Configuration functions for the command line interface
3
- class Config < Base
4
-
5
- desc "set key value", t("cli.config.set")
6
- thor_options(self, Translatomatic::CLI::CommonOptions)
7
- # Change a configuration setting
8
- # @param key [String] configuration key
9
- # @param value [String] new value for the configuration
10
- # @return [String] the new value
11
- def set(key, value)
12
- run { conf.set(key, value) }
13
- end
14
-
15
- desc "remove key", t("cli.config.remove")
16
- thor_options(self, Translatomatic::CLI::CommonOptions)
17
- # Remove a configuration setting
18
- # @param key [String] configuration key to remove
19
- # @return [void]
20
- def remove(key)
21
- run { conf.remove(key) }
22
- end
23
-
24
- desc "list", t("cli.config.list")
25
- thor_options(self, Translatomatic::CLI::CommonOptions)
26
- # List current configuration settings
27
- def list
28
- run do
29
- puts t("cli.config.configuration")
30
- print_config_table(:key, :value)
31
- end
32
- end
33
-
34
- desc "describe", t("cli.config.describe")
35
- thor_options(self, Translatomatic::CLI::CommonOptions)
36
- # Describe available configuration settings
37
- def describe
38
- run do
39
- puts t("cli.config.configuration")
40
- print_config_table(:key, :type, :desc)
41
- end
42
- end
43
-
44
- private
45
-
46
- TABLE_HEADING_MAP = {
47
- key: t("cli.config.name"),
48
- type: t("cli.config.type"),
49
- value: t("cli.config.value"),
50
- desc: t("cli.config.desc"),
51
- }
52
-
53
- def print_config_table(*columns)
54
- puts
55
- rows = []
56
- rows << columns.collect { |i| TABLE_HEADING_MAP[i] }
57
- rows << rows[0].collect { |i| i.gsub(/\w/, '=') }
58
- Translatomatic::Config.options.each do |option|
59
- key = option.name.to_s
60
- data = []
61
- columns.each do |column|
62
- data << case column
63
- when :key
64
- key
65
- when :value
66
- value = conf.get(key)
67
- value.nil? ? "-" : value
68
- when :type
69
- t("config.types.#{option.type}")
70
- when :desc
71
- option.description
72
- end
73
- end
74
- rows << data
75
- end
76
- rows.sort_by { |i| i[0] }
77
- print_table(rows, indent: 2)
78
- puts
79
- end
80
- end
81
- end
1
+ module Translatomatic::CLI
2
+ # Configuration functions for the command line interface
3
+ class Config < Base
4
+
5
+ define_options(
6
+ { name: :context, type: :string, aliases: "-c",
7
+ desc: t("cli.config.context"),
8
+ enum: Translatomatic::Config::CONTEXTS,
9
+ command_line_only: true
10
+ },
11
+ )
12
+
13
+ desc "set key value", t("cli.config.set")
14
+ thor_options(self, Translatomatic::CLI::CommonOptions)
15
+ thor_options(self, Translatomatic::CLI::Config)
16
+ # Change a configuration setting
17
+ # @param key [String] configuration key
18
+ # @param value [String] new value for the configuration
19
+ # @return [String] the new value
20
+ def set(key, *value)
21
+ run { conf.set(key, value, cli_option(:context)) }
22
+ end
23
+
24
+ desc "remove key", t("cli.config.remove")
25
+ thor_options(self, Translatomatic::CLI::CommonOptions)
26
+ thor_options(self, Translatomatic::CLI::Config)
27
+ # Remove a configuration setting
28
+ # @param key [String] configuration key to remove
29
+ # @return [void]
30
+ def remove(key)
31
+ run { conf.remove(key, cli_option(:context)) }
32
+ end
33
+
34
+ desc "list", t("cli.config.list")
35
+ thor_options(self, Translatomatic::CLI::CommonOptions)
36
+ thor_options(self, Translatomatic::CLI::Config)
37
+ # List current configuration settings
38
+ def list
39
+ run do
40
+ print_config_table(columns: [:key, :value],
41
+ context: cli_option(:context),
42
+ skip_blanks: true
43
+ )
44
+ end
45
+ end
46
+
47
+ desc "describe", t("cli.config.describe")
48
+ thor_options(self, Translatomatic::CLI::CommonOptions)
49
+ thor_options(self, Translatomatic::CLI::Config)
50
+ # Describe available configuration settings
51
+ def describe
52
+ run do
53
+ print_config_table(columns: [:key, :type, :desc])
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ CONFIG_HEADING_MAP = {
60
+ key: t("cli.config.name"),
61
+ type: t("cli.config.type"),
62
+ value: t("cli.config.value"),
63
+ desc: t("cli.config.desc"),
64
+ }
65
+
66
+ def print_config_table(options)
67
+ columns = options[:columns]
68
+ context = options[:context]
69
+ rows = []
70
+
71
+ if context
72
+ puts t("cli.config.context_configuration", context: context)
73
+ else
74
+ puts t("cli.config.configuration")
75
+ end
76
+ puts
77
+ Translatomatic::Config.options.each do |option|
78
+ key = option.name.to_s
79
+ next if option.command_line_only
80
+ next if options[:skip_blanks] && !conf.include?(key, context)
81
+ value = conf.get(key, context)
82
+ data = []
83
+ columns.each do |column|
84
+ data << case column
85
+ when :key
86
+ key
87
+ when :value
88
+ value.nil? ? "-" : value
89
+ when :type
90
+ t("config.types.#{option.type}")
91
+ when :desc
92
+ option.description
93
+ end
94
+ end
95
+ rows << data
96
+ end
97
+
98
+ if rows.empty?
99
+ puts t("cli.config.no_config")
100
+ else
101
+ rows.sort_by { |i| i[0] }
102
+ headings = columns.collect { |i| CONFIG_HEADING_MAP[i] }
103
+ rows.unshift headings.collect { |i| i.gsub(/\w/, '=') }
104
+ rows.unshift headings
105
+ print_table(rows, indent: 2)
106
+ end
107
+ puts
108
+ end
109
+ end
110
+ end
@@ -1,15 +1,16 @@
1
- # Command line interface to translatomatic
1
+ # Command line interface to translatomatic
2
2
  module Translatomatic::CLI
3
3
  # Main command line interface
4
- class Main < Base
4
+ class Main < Base
5
+
6
+ default_task :translate
5
7
 
6
8
  begin
7
- config = Translatomatic::Config.instance
8
- I18n.default_locale = config.default_locale
9
+ I18n.default_locale = Translatomatic.config.default_locale
9
10
  end
10
-
11
- package_name "Translatomatic"
12
- map %W[-v --version] => :version
11
+
12
+ package_name "Translatomatic"
13
+ map %W[-v --version] => :version
13
14
  map %W[-L --list] => :translators
14
15
 
15
16
  desc "translate", t("cli.translate.subcommand")
@@ -20,8 +21,8 @@ module Translatomatic::CLI
20
21
 
21
22
  desc "config", t("cli.config.subcommand")
22
23
  subcommand "config", Config
23
-
24
- desc "display file [key...]", t("cli.display_values")
24
+
25
+ desc "display file [key...]", t("cli.display_values")
25
26
  thor_options(self, Translatomatic::CLI::CommonOptions)
26
27
  method_option :locales, type: :string, desc: t("cli.locales_to_display")
27
28
  method_option :sentences, type: :boolean, desc: t("cli.display_sentences")
@@ -29,84 +30,96 @@ module Translatomatic::CLI
29
30
  # @param file [String] Path to resource file
30
31
  # @param keys [Array<String>] Optional list of locales
31
32
  # @return [void]
32
- def display(file, *keys)
33
- run do
34
- source = Translatomatic::ResourceFile.load(file)
35
- keys = source.properties.keys if keys.empty?
36
- display_keys(source, keys)
37
-
38
- # TODO: if locales not specified, determine the list of locales from
33
+ def display(file, *keys)
34
+ run do
35
+ source = Translatomatic::ResourceFile.load(file)
36
+ keys = source.properties.keys if keys.empty?
37
+ display_keys(source, keys)
38
+
39
+ # TODO: if locales not specified, determine the list of locales from
39
40
  # all the files in the resource bundle.
40
41
  locales = parse_list(options[:locales])
41
42
  locales << Translatomatic::Locale.default.to_s if locales.empty?
42
43
  locales.each do |tag|
43
44
  locale = locale(tag)
44
45
  next if locale == source.locale
45
- display_properties(source, keys, locale)
46
- end
47
- end
48
- end
49
-
46
+ display_properties(source, keys, locale)
47
+ end
48
+ end
49
+ end
50
+
50
51
  desc "strings file [file...]", t("cli.extract_strings")
51
52
  thor_options(self, Translatomatic::CLI::CommonOptions)
52
53
  # Extract strings from non-resource files
53
54
  # @param files [Array<String>] List of paths to files
54
- # @return [void]
55
- def strings(*files)
56
- run do
57
- strings = []
58
- files.each do |file|
59
- extractor = Translatomatic::Extractor::Base.new(file)
60
- strings << extractor.extract
61
- end
62
- puts strings.join("\n")
63
- end
64
- end
65
-
55
+ # @return [void]
56
+ def strings(*files)
57
+ run do
58
+ strings = []
59
+ files.each do |file|
60
+ extractor = Translatomatic::Extractor::Base.new(file)
61
+ strings << extractor.extract
62
+ end
63
+ puts strings.join("\n")
64
+ end
65
+ end
66
+
67
+ desc "convert source target", t("cli.convert")
68
+ # Convert a resource file from one format to another
69
+ # @param source [String] An existing resource file
70
+ # @param target [String] The name of a target resource file
71
+ # @return [void]
72
+ def convert(source, target)
73
+ run do
74
+ converter = Translatomatic::Converter.new
75
+ converter.convert(source, target)
76
+ end
77
+ end
78
+
66
79
  desc "services", t("cli.list_backends")
67
80
  thor_options(self, Translatomatic::CLI::CommonOptions)
68
81
  # List available translator services
69
- # @return [void]
70
- def services
71
- run { puts Translatomatic::Translator.list }
72
- end
73
-
82
+ # @return [void]
83
+ def services
84
+ run { puts Translatomatic::Translator.list }
85
+ end
86
+
74
87
  desc 'version', t("cli.display_version")
75
88
  thor_options(self, Translatomatic::CLI::CommonOptions)
76
89
  # Display version number
77
- # @return [void]
78
- def version
79
- puts "Translatomatic v#{Translatomatic::VERSION}"
80
- end
81
-
82
- private
83
-
84
- def display_properties(source, keys, locale)
85
- path = source.locale_path(locale)
86
- if path.exist?
87
- resource = Translatomatic::ResourceFile.load(path)
88
- display_keys(resource, keys)
89
- end
90
- end
91
-
92
- def display_keys(source, keys)
90
+ # @return [void]
91
+ def version
92
+ puts "Translatomatic v#{Translatomatic::VERSION}"
93
+ end
94
+
95
+ private
96
+
97
+ def display_properties(source, keys, locale)
98
+ path = source.locale_path(locale)
99
+ if path.exist?
100
+ resource = Translatomatic::ResourceFile.load(path)
101
+ display_keys(resource, keys)
102
+ end
103
+ end
104
+
105
+ def display_keys(source, keys)
93
106
  puts t("cli.file_source", file: source)
94
- rows = []
95
- keys.each do |key|
96
- value = source.get(key)
97
- rows << [key + ":", value]
98
- end
99
- print_table(rows, indent: 2)
100
-
101
- if options[:sentences]
107
+ rows = []
108
+ keys.each do |key|
109
+ value = source.get(key)
110
+ rows << [key + ":", value]
111
+ end
112
+ print_table(rows, indent: 2)
113
+
114
+ if options[:sentences]
102
115
  puts t("cli.sentences")
103
- source.sentences.each do |sentence|
104
- puts "- " + sentence.to_s
105
- end
106
- end
107
-
108
- puts
109
- end
110
-
111
- end # class
112
- end # module
116
+ source.sentences.each do |sentence|
117
+ puts "- " + sentence.to_s
118
+ end
119
+ end
120
+
121
+ puts
122
+ end
123
+
124
+ end # class
125
+ end # module
@@ -1,16 +1,25 @@
1
- # Command line interface to translatomatic
1
+ require 'ruby-progressbar'
2
+
3
+ # Command line interface to translatomatic
2
4
  module Translatomatic::CLI
3
- # Translation functions for the command line interface
4
- class Translate < Base
5
+ # Translation functions for the command line interface
6
+ class Translate < Base
7
+
8
+ default_task :file
5
9
 
6
10
  define_options(
7
11
  { name: :translator, type: :array, aliases: "-t",
8
- desc: t("converter.translator"), enum: Translatomatic::Translator.names
12
+ desc: t("cli.translate.translator"),
13
+ enum: Translatomatic::Translator.names
9
14
  },
10
15
  { name: :source_locale, desc: t("cli.source_locale") },
11
16
  { name: :share, desc: t("cli.share"), default: false },
12
17
  { name: :target_locales, desc: t("cli.target_locales"),
13
- type: :array, hidden: true },
18
+ type: :array
19
+ },
20
+ { name: :source_files, desc: t("cli.source_files"),
21
+ type: :array
22
+ },
14
23
  )
15
24
 
16
25
  desc "string text locale...", t("cli.translate.string")
@@ -19,11 +28,13 @@ module Translatomatic::CLI
19
28
  thor_options(self, Translatomatic::Translator.modules)
20
29
  # Translate a string to target locales
21
30
  # @param text [String] String to translate
22
- # @param locales [Array<String>] List of target locales
31
+ # @param locales [Array<String>] List of target locales, can also be set
32
+ # with the --target-locales option
23
33
  # @return [void]
24
34
  def string(text, *locales)
25
35
  run do
26
- setup_translation(locales)
36
+ setup_translation
37
+ determine_target_locales(locales)
27
38
 
28
39
  puts "(%s) %s" % [@source_locale, text]
29
40
  @translators.each do |translator|
@@ -38,109 +49,133 @@ module Translatomatic::CLI
38
49
  finish_log
39
50
  end
40
51
  end
41
-
42
- desc "file filename locale...", t("cli.translate.file")
52
+
53
+ desc "file filename locale...", t("cli.translate.file")
43
54
  thor_options(self, Translatomatic::CLI::CommonOptions)
44
55
  thor_options(self, Translatomatic::CLI::Translate)
45
- thor_options(self, Translatomatic::Converter)
56
+ thor_options(self, Translatomatic::FileTranslator)
46
57
  thor_options(self, Translatomatic::Database)
47
58
  thor_options(self, Translatomatic::Translator.modules)
48
59
  # Translate files to target locales
49
- # @param file [String] Resource file to translate
50
- # @param locales [Array<String>] List of target locales
60
+ # @param file [String] Resource file to translate, can also be set
61
+ # with the --source-files option.
62
+ # @param locales [Array<String>] List of target locales, can also be set
63
+ # with the --target-locales option
51
64
  # @return [void]
52
- def file(file, *locales)
53
- run do
54
- setup_translation(locales)
55
-
56
- # load source file
57
- raise t("cli.file_not_found", file: file) unless File.exist?(file)
58
- source = Translatomatic::ResourceFile.load(file, @source_locale)
59
- raise t("cli.file_unsupported", file: file) unless source
60
-
61
- # set up database
62
- Translatomatic::Database.new(options)
63
-
64
- log.debug(t("cli.locales_properties", locales: locales, properties: source.properties.length))
65
-
66
- # set up converter
67
- translation_count = calculate_translation_count(source, @target_locales)
68
- converter_options = options.merge(
69
- translator: @translators,
70
- listener: progress_updater(translation_count)
71
- )
72
- converter = Translatomatic::Converter.new(converter_options)
73
-
74
- # convert source to locale(s) and write files
75
- @target_locales.each do |i|
76
- to_locale = locale(i)
77
- next if to_locale.language == source.locale.language
78
- converter.translate_to_file(source, to_locale)
79
- end
80
-
81
- log.info converter.stats
82
- finish_log
83
-
84
- share_translations(converter) if cli_option(:share)
85
- end
86
- end
87
-
88
- private
89
-
90
- def setup_translation(locales)
91
- log.info(t("cli.dry_run")) if cli_option(:dry_run)
92
-
93
- @target_locales = parse_list(locales, cli_option(:target_locales))
94
- @source_locale = determine_source_locale
95
- raise t("cli.locales_required") if @target_locales.empty?
96
- conf.logger.level = Logger::DEBUG if cli_option(:debug)
97
-
98
- # resolve translators
99
- @translators = Translatomatic::Translator.resolve(
100
- cli_option(:translator), options
101
- )
102
- end
103
-
104
- def determine_source_locale
105
- cli_option(:source_locale) || conf.default_locale
106
- end
107
-
108
- def calculate_translation_count(source, locales)
109
- source.sentences.length * locales.length
110
- end
111
-
112
- def share_translations(converter)
113
- return if converter.db_translations.empty?
114
-
115
- tmx = Translatomatic::TMX::Document.from_texts(converter.db_translations)
116
- available = Translatomatic::Translator.available(options)
117
- available.each do |translator|
118
- if translator.respond_to?(:upload)
65
+ def file(file = nil, *locales)
66
+ run do
67
+ setup_translation
68
+ determine_target_locales(locales)
69
+
70
+ # check source file(s) exist and they can be loaded
71
+ source_files = parse_list(cli_option(:source_files), file)
72
+ source_files.each do |source_file|
73
+ path = source_path(source_file)
74
+ raise t("file.not_found", file: path) unless File.exist?(path)
75
+ source = Translatomatic::ResourceFile.load(path, @source_locale)
76
+ raise t("file.unsupported", file: path) unless source
77
+ end
78
+
79
+ # set up database
80
+ Translatomatic::Database.new(options)
81
+
82
+ # set up file translatiln
83
+ translation_count = calculate_translation_count(source_files, @target_locales)
84
+ ft_options = options.merge(
85
+ translator: @translators,
86
+ listener: progress_updater(translation_count)
87
+ )
88
+ ft = Translatomatic::FileTranslator.new(ft_options)
89
+
90
+ source_files.each do |path|
91
+ # read source file
92
+ source = Translatomatic::ResourceFile.load(path, @source_locale)
93
+
94
+ # convert source to locale(s) and write files
95
+ @target_locales.each do |i|
96
+ to_locale = locale(i)
97
+ next if to_locale.language == source.locale.language
98
+ ft.translate_to_file(source, to_locale)
99
+ end
100
+ end
101
+
102
+ log.info ft.stats
103
+ finish_log
104
+
105
+ share_translations(ft) if cli_option(:share)
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def setup_translation
112
+ @source_locale = determine_source_locale
113
+ # resolve translators
114
+ @translators = Translatomatic::Translator.resolve(
115
+ cli_option(:translator), options
116
+ )
117
+ end
118
+
119
+ def determine_target_locales(locales)
120
+ @target_locales = parse_list(locales, cli_option(:target_locales))
121
+ raise t("cli.locales_required") if @target_locales.empty?
122
+ end
123
+
124
+ def determine_source_locale
125
+ cli_option(:source_locale) || conf.default_locale
126
+ end
127
+
128
+ def calculate_translation_count(source_files, locales)
129
+ count = 0
130
+ source_files.each do |file|
131
+ source = Translatomatic::ResourceFile.load(file, @source_locale)
132
+ count += source.sentences.length * locales.length
133
+ end
134
+ count
135
+ end
136
+
137
+ def share_translations(ft)
138
+ return if ft.db_translations.empty?
139
+
140
+ tmx = Translatomatic::TMX::Document.from_texts(ft.db_translations)
141
+ available = Translatomatic::Translator.available(options)
142
+ available.each do |translator|
143
+ if translator.respond_to?(:upload)
119
144
  log.info(t("cli.uploading_tmx", name: translator.name))
120
- translator.upload(tmx)
121
- end
122
- end
123
-
124
- ActiveRecord::Base.transaction do
125
- converter.db_translations.each do |text|
126
- text.update(shared: true) if text.is_translated?
127
- end
128
- end
129
- end
130
-
131
- # create a progress bar and progress updater
132
- def progress_updater(translation_count)
133
- return nil unless cli_option(:wank)
134
- # set up progress bar
135
- progressbar = ProgressBar.create(
136
- title: t("cli.translating"),
137
- format: "%t: |%B| %E ",
138
- autofinish: false,
139
- total: translation_count
140
- )
141
- conf.logger.progressbar = progressbar
142
- Translatomatic::ProgressUpdater.new(progressbar)
143
- end
144
-
145
- end # class
146
- end # module
145
+ translator.upload(tmx)
146
+ end
147
+ end
148
+
149
+ ActiveRecord::Base.transaction do
150
+ ft.db_translations.each do |text|
151
+ text.update(shared: true) if text.is_translated?
152
+ end
153
+ end
154
+ end
155
+
156
+ # convert the given path to an absolute path if necessary, relative
157
+ # to project root.
158
+ def source_path(path)
159
+ if path.start_with?("~/")
160
+ # replace ~/ with home directory
161
+ path = path.sub(/\A~\//, Dir.home + "/")
162
+ end
163
+ File.absolute_path(path, conf.project_path)
164
+ end
165
+
166
+ # create a progress bar and progress updater
167
+ def progress_updater(translation_count)
168
+ return nil unless cli_option(:wank)
169
+ # set up progress bar
170
+ progressbar = ProgressBar.create(
171
+ title: t("cli.translating"),
172
+ format: "%t: |%B| %E ",
173
+ autofinish: false,
174
+ total: translation_count
175
+ )
176
+ conf.logger.progressbar = progressbar
177
+ Translatomatic::ProgressUpdater.new(progressbar)
178
+ end
179
+
180
+ end # class
181
+ end # module