puppet 5.3.3-x86-mingw32 → 5.3.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (291) hide show
  1. data/CONTRIBUTING.md +1 -1
  2. data/Gemfile +3 -0
  3. data/ext/puppet-test +3 -2
  4. data/lib/hiera/puppet_function.rb +5 -2
  5. data/lib/hiera_puppet.rb +3 -3
  6. data/lib/puppet.rb +2 -5
  7. data/lib/puppet/agent.rb +22 -2
  8. data/lib/puppet/agent/locker.rb +6 -5
  9. data/lib/puppet/application.rb +18 -1
  10. data/lib/puppet/application/agent.rb +9 -2
  11. data/lib/puppet/application/apply.rb +1 -1
  12. data/lib/puppet/application/config.rb +1 -0
  13. data/lib/puppet/application/device.rb +1 -2
  14. data/lib/puppet/application/filebucket.rb +22 -5
  15. data/lib/puppet/application/help.rb +1 -0
  16. data/lib/puppet/application/lookup.rb +1 -3
  17. data/lib/puppet/application_support.rb +6 -1
  18. data/lib/puppet/bindings.rb +2 -1
  19. data/lib/puppet/configurer.rb +9 -4
  20. data/lib/puppet/configurer/downloader_factory.rb +10 -0
  21. data/lib/puppet/configurer/plugin_handler.rb +11 -4
  22. data/lib/puppet/daemon.rb +2 -2
  23. data/lib/puppet/defaults.rb +99 -27
  24. data/lib/puppet/environments.rb +2 -0
  25. data/lib/puppet/error.rb +5 -15
  26. data/lib/puppet/external/pson/common.rb +2 -2
  27. data/lib/puppet/face/catalog.rb +1 -1
  28. data/lib/puppet/face/config.rb +14 -1
  29. data/lib/puppet/face/epp.rb +4 -2
  30. data/lib/puppet/face/help.rb +12 -14
  31. data/lib/puppet/face/man.rb +1 -0
  32. data/lib/puppet/face/module/build.rb +1 -1
  33. data/lib/puppet/face/module/list.rb +6 -17
  34. data/lib/puppet/face/module/uninstall.rb +14 -3
  35. data/lib/puppet/face/node.rb +1 -0
  36. data/lib/puppet/face/status.rb +1 -0
  37. data/lib/puppet/file_serving/base.rb +2 -1
  38. data/lib/puppet/file_serving/configuration.rb +3 -0
  39. data/lib/puppet/file_serving/configuration/parser.rb +23 -9
  40. data/lib/puppet/file_serving/mount/locales.rb +35 -0
  41. data/lib/puppet/forge.rb +2 -1
  42. data/lib/puppet/forge/errors.rb +24 -22
  43. data/lib/puppet/functions/binary_file.rb +1 -0
  44. data/lib/puppet/functions/each.rb +10 -4
  45. data/lib/puppet/functions/eyaml_lookup_key.rb +4 -2
  46. data/lib/puppet/functions/lookup.rb +2 -2
  47. data/lib/puppet/functions/map.rb +12 -2
  48. data/lib/puppet/functions/slice.rb +2 -3
  49. data/lib/puppet/functions/unique.rb +1 -1
  50. data/lib/puppet/functions/yaml_data.rb +1 -1
  51. data/lib/puppet/gettext/config.rb +144 -41
  52. data/lib/puppet/gettext/module_translations.rb +42 -0
  53. data/lib/puppet/graph/relationship_graph.rb +1 -1
  54. data/lib/puppet/graph/simple_graph.rb +3 -3
  55. data/lib/puppet/indirector/catalog/compiler.rb +40 -25
  56. data/lib/puppet/indirector/exec.rb +1 -1
  57. data/lib/puppet/indirector/facts/facter.rb +3 -3
  58. data/lib/puppet/indirector/facts/network_device.rb +2 -2
  59. data/lib/puppet/indirector/file_bucket_file/file.rb +4 -1
  60. data/lib/puppet/indirector/indirection.rb +17 -9
  61. data/lib/puppet/indirector/ldap.rb +2 -2
  62. data/lib/puppet/indirector/node/write_only_yaml.rb +3 -1
  63. data/lib/puppet/indirector/rest.rb +8 -5
  64. data/lib/puppet/indirector/ssl_file.rb +2 -2
  65. data/lib/puppet/indirector/terminus.rb +3 -3
  66. data/lib/puppet/interface.rb +2 -1
  67. data/lib/puppet/interface/action.rb +41 -24
  68. data/lib/puppet/interface/action_builder.rb +14 -5
  69. data/lib/puppet/interface/action_manager.rb +1 -1
  70. data/lib/puppet/interface/documentation.rb +21 -10
  71. data/lib/puppet/interface/face_collection.rb +4 -2
  72. data/lib/puppet/interface/option.rb +36 -15
  73. data/lib/puppet/interface/option_builder.rb +23 -9
  74. data/lib/puppet/interface/option_manager.rb +8 -3
  75. data/lib/puppet/metatype/manager.rb +7 -3
  76. data/lib/puppet/module.rb +18 -21
  77. data/lib/puppet/module_tool/errors/installer.rb +18 -20
  78. data/lib/puppet/module_tool/errors/shared.rb +20 -15
  79. data/lib/puppet/module_tool/errors/uninstaller.rb +1 -0
  80. data/lib/puppet/module_tool/errors/upgrader.rb +1 -1
  81. data/lib/puppet/module_tool/tar/mini.rb +57 -4
  82. data/lib/puppet/network/auth_config_parser.rb +18 -13
  83. data/lib/puppet/network/authstore.rb +2 -2
  84. data/lib/puppet/network/client_request.rb +1 -1
  85. data/lib/puppet/network/format.rb +3 -3
  86. data/lib/puppet/network/http/api/indirection_type.rb +1 -1
  87. data/lib/puppet/network/http/api/master/v3/environment.rb +5 -2
  88. data/lib/puppet/network/http/error.rb +7 -7
  89. data/lib/puppet/network/http/factory.rb +9 -0
  90. data/lib/puppet/network/http/rack.rb +2 -2
  91. data/lib/puppet/network/http/webrick.rb +2 -4
  92. data/lib/puppet/node.rb +25 -6
  93. data/lib/puppet/node/environment.rb +14 -0
  94. data/lib/puppet/node/facts.rb +9 -0
  95. data/lib/puppet/parameter.rb +3 -3
  96. data/lib/puppet/parameter/value_collection.rb +9 -9
  97. data/lib/puppet/parser/ast/leaf.rb +1 -1
  98. data/lib/puppet/parser/ast/node.rb +2 -2
  99. data/lib/puppet/parser/ast/pops_bridge.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +6 -5
  101. data/lib/puppet/parser/functions.rb +1 -1
  102. data/lib/puppet/parser/functions/generate.rb +2 -4
  103. data/lib/puppet/parser/functions/inline_template.rb +1 -2
  104. data/lib/puppet/parser/functions/sprintf.rb +17 -3
  105. data/lib/puppet/parser/functions/template.rb +6 -2
  106. data/lib/puppet/parser/resource.rb +30 -31
  107. data/lib/puppet/parser/scope.rb +20 -11
  108. data/lib/puppet/parser/templatewrapper.rb +4 -3
  109. data/lib/puppet/pops/evaluator/collector_transformer.rb +2 -1
  110. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +1 -1
  111. data/lib/puppet/pops/evaluator/epp_evaluator.rb +21 -8
  112. data/lib/puppet/pops/evaluator/evaluator_impl.rb +2 -1
  113. data/lib/puppet/pops/evaluator/external_syntax_support.rb +1 -1
  114. data/lib/puppet/pops/evaluator/runtime3_converter.rb +3 -1
  115. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +1 -1
  116. data/lib/puppet/pops/evaluator/runtime3_support.rb +4 -4
  117. data/lib/puppet/pops/functions/dispatch.rb +1 -1
  118. data/lib/puppet/pops/functions/function.rb +8 -2
  119. data/lib/puppet/pops/issue_reporter.rb +7 -2
  120. data/lib/puppet/pops/issues.rb +10 -4
  121. data/lib/puppet/pops/label_provider.rb +1 -1
  122. data/lib/puppet/pops/loader/module_loaders.rb +5 -2
  123. data/lib/puppet/pops/loader/static_loader.rb +1 -1
  124. data/lib/puppet/pops/loaders.rb +7 -3
  125. data/lib/puppet/pops/lookup/explainer.rb +2 -1
  126. data/lib/puppet/pops/lookup/hiera_config.rb +2 -2
  127. data/lib/puppet/pops/lookup/lookup_adapter.rb +4 -4
  128. data/lib/puppet/pops/merge_strategy.rb +6 -3
  129. data/lib/puppet/pops/migration/migration_checker.rb +8 -8
  130. data/lib/puppet/pops/model/ast_transformer.rb +1 -1
  131. data/lib/puppet/pops/model/factory.rb +4 -2
  132. data/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  133. data/lib/puppet/pops/serialization/abstract_writer.rb +2 -1
  134. data/lib/puppet/pops/types/iterable.rb +2 -0
  135. data/lib/puppet/pops/types/p_object_type.rb +36 -15
  136. data/lib/puppet/pops/types/type_calculator.rb +2 -1
  137. data/lib/puppet/pops/types/type_factory.rb +3 -1
  138. data/lib/puppet/pops/types/type_mismatch_describer.rb +19 -6
  139. data/lib/puppet/pops/types/type_parser.rb +7 -7
  140. data/lib/puppet/pops/types/types.rb +10 -4
  141. data/lib/puppet/pops/validation.rb +14 -12
  142. data/lib/puppet/property.rb +14 -6
  143. data/lib/puppet/property/ensure.rb +2 -2
  144. data/lib/puppet/provider.rb +4 -4
  145. data/lib/puppet/provider/group/aix.rb +4 -2
  146. data/lib/puppet/provider/ldap.rb +2 -2
  147. data/lib/puppet/provider/naginator.rb +1 -1
  148. data/lib/puppet/provider/nameservice.rb +7 -4
  149. data/lib/puppet/provider/nameservice/directoryservice.rb +4 -3
  150. data/lib/puppet/provider/package/aix.rb +1 -1
  151. data/lib/puppet/provider/package/nim.rb +7 -8
  152. data/lib/puppet/provider/package/opkg.rb +1 -1
  153. data/lib/puppet/provider/package/pkg.rb +9 -6
  154. data/lib/puppet/provider/package/pkgutil.rb +3 -3
  155. data/lib/puppet/provider/package/yum.rb +1 -1
  156. data/lib/puppet/provider/parsedfile.rb +4 -4
  157. data/lib/puppet/provider/selmodule/semodule.rb +5 -3
  158. data/lib/puppet/provider/service/base.rb +1 -1
  159. data/lib/puppet/provider/service/init.rb +1 -1
  160. data/lib/puppet/provider/service/launchd.rb +2 -2
  161. data/lib/puppet/provider/service/runit.rb +2 -1
  162. data/lib/puppet/provider/service/smf.rb +2 -0
  163. data/lib/puppet/provider/service/systemd.rb +1 -0
  164. data/lib/puppet/provider/service/upstart.rb +1 -1
  165. data/lib/puppet/provider/user/aix.rb +13 -6
  166. data/lib/puppet/provider/user/openbsd.rb +2 -1
  167. data/lib/puppet/provider/yumrepo/inifile.rb +2 -1
  168. data/lib/puppet/provider/zone/solaris.rb +2 -2
  169. data/lib/puppet/reference/configuration.rb +4 -2
  170. data/lib/puppet/relationship.rb +2 -1
  171. data/lib/puppet/reports/store.rb +1 -1
  172. data/lib/puppet/resource.rb +7 -5
  173. data/lib/puppet/resource/capability_finder.rb +14 -11
  174. data/lib/puppet/resource/catalog.rb +33 -18
  175. data/lib/puppet/resource/type.rb +5 -5
  176. data/lib/puppet/settings.rb +19 -13
  177. data/lib/puppet/settings/base_setting.rb +23 -8
  178. data/lib/puppet/settings/config_file.rb +14 -4
  179. data/lib/puppet/settings/environment_conf.rb +19 -9
  180. data/lib/puppet/ssl/base.rb +9 -4
  181. data/lib/puppet/ssl/oids.rb +8 -2
  182. data/lib/puppet/syntax_checkers/base64.rb +5 -6
  183. data/lib/puppet/transaction.rb +7 -3
  184. data/lib/puppet/transaction/persistence.rb +16 -1
  185. data/lib/puppet/transaction/report.rb +6 -0
  186. data/lib/puppet/type.rb +27 -35
  187. data/lib/puppet/type/file.rb +2 -1
  188. data/lib/puppet/type/file/data_sync.rb +2 -1
  189. data/lib/puppet/type/file/source.rb +1 -1
  190. data/lib/puppet/type/group.rb +1 -1
  191. data/lib/puppet/type/mount.rb +1 -1
  192. data/lib/puppet/type/resources.rb +1 -1
  193. data/lib/puppet/type/schedule.rb +26 -14
  194. data/lib/puppet/type/user.rb +9 -3
  195. data/lib/puppet/type/zone.rb +1 -1
  196. data/lib/puppet/util.rb +27 -21
  197. data/lib/puppet/util/at_fork/solaris.rb +6 -4
  198. data/lib/puppet/util/command_line.rb +5 -0
  199. data/lib/puppet/util/command_line/trollop.rb +6 -5
  200. data/lib/puppet/util/errors.rb +61 -8
  201. data/lib/puppet/util/fileparsing.rb +3 -5
  202. data/lib/puppet/util/http_proxy.rb +14 -6
  203. data/lib/puppet/util/instance_loader.rb +1 -3
  204. data/lib/puppet/util/ldap/manager.rb +6 -3
  205. data/lib/puppet/util/log.rb +19 -24
  206. data/lib/puppet/util/logging.rb +21 -28
  207. data/lib/puppet/util/methodhelper.rb +1 -1
  208. data/lib/puppet/util/nagios_maker.rb +1 -1
  209. data/lib/puppet/util/network_device/config.rb +21 -13
  210. data/lib/puppet/util/plist.rb +3 -1
  211. data/lib/puppet/util/posix.rb +1 -1
  212. data/lib/puppet/util/provider_features.rb +1 -1
  213. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +1 -1
  214. data/lib/puppet/util/reference.rb +2 -3
  215. data/lib/puppet/util/selinux.rb +1 -1
  216. data/lib/puppet/util/storage.rb +2 -2
  217. data/lib/puppet/util/windows/eventlog.rb +10 -5
  218. data/lib/puppet/util/windows/file.rb +61 -9
  219. data/lib/puppet/util/windows/process.rb +1 -1
  220. data/lib/puppet/util/windows/taskscheduler.rb +2 -2
  221. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet.rb +5 -1
  222. data/lib/puppet/version.rb +1 -1
  223. data/locales/en/puppet.po +19 -0
  224. data/locales/ja/puppet.po +2739 -809
  225. data/locales/puppet.pot +2367 -734
  226. data/spec/fixtures/unit/application/environments/production/data/common.yaml +2 -0
  227. data/spec/integration/agent/logging_spec.rb +2 -0
  228. data/spec/integration/faces/plugin_spec.rb +1 -0
  229. data/spec/integration/network/authconfig_spec.rb +2 -2
  230. data/spec/integration/parser/collection_spec.rb +2 -2
  231. data/spec/integration/parser/scope_spec.rb +16 -3
  232. data/spec/integration/provider/cron/crontab_spec.rb +1 -0
  233. data/spec/integration/transaction/report_spec.rb +5 -0
  234. data/spec/lib/matchers/json.rb +14 -13
  235. data/spec/unit/agent_spec.rb +33 -0
  236. data/spec/unit/application/config_spec.rb +4 -0
  237. data/spec/unit/application/lookup_spec.rb +30 -0
  238. data/spec/unit/application_spec.rb +18 -0
  239. data/spec/unit/configurer/downloader_factory_spec.rb +33 -0
  240. data/spec/unit/configurer/plugin_handler_spec.rb +71 -16
  241. data/spec/unit/environments_spec.rb +15 -0
  242. data/spec/unit/face/config_spec.rb +8 -9
  243. data/spec/unit/face/epp_face_spec.rb +2 -2
  244. data/spec/unit/face/plugin_spec.rb +50 -4
  245. data/spec/unit/file_serving/configuration/parser_spec.rb +2 -2
  246. data/spec/unit/file_serving/mount/locales_spec.rb +73 -0
  247. data/spec/unit/functions/break_spec.rb +108 -50
  248. data/spec/unit/functions/defined_spec.rb +2 -2
  249. data/spec/unit/functions/hiera_spec.rb +0 -1
  250. data/spec/unit/functions/lookup_spec.rb +85 -19
  251. data/spec/unit/functions/next_spec.rb +1 -1
  252. data/spec/unit/functions/return_spec.rb +2 -2
  253. data/spec/unit/gettext/config_spec.rb +125 -0
  254. data/spec/unit/gettext/module_loading_spec.rb +53 -0
  255. data/spec/unit/indirector/json_spec.rb +0 -11
  256. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  257. data/spec/unit/info_service_spec.rb +1 -1
  258. data/spec/unit/interface_spec.rb +12 -0
  259. data/spec/unit/module_spec.rb +0 -28
  260. data/spec/unit/module_tool/tar/mini_spec.rb +34 -5
  261. data/spec/unit/network/http/factory_spec.rb +22 -0
  262. data/spec/unit/network/http/webrick_spec.rb +30 -29
  263. data/spec/unit/node/environment_spec.rb +16 -0
  264. data/spec/unit/node_spec.rb +102 -16
  265. data/spec/unit/parser/environment_compiler_spec.rb +1 -1
  266. data/spec/unit/parser/functions/sprintf_spec.rb +26 -0
  267. data/spec/unit/parser/resource/param_spec.rb +1 -1
  268. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +9 -9
  269. data/spec/unit/pops/loaders/static_loader_spec.rb +1 -1
  270. data/spec/unit/pops/parser/parse_containers_spec.rb +1 -1
  271. data/spec/unit/pops/types/type_calculator_spec.rb +40 -0
  272. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +9 -0
  273. data/spec/unit/provider/selmodule_spec.rb +6 -0
  274. data/spec/unit/provider/service/init_spec.rb +1 -1
  275. data/spec/unit/provider/service/smf_spec.rb +2 -0
  276. data/spec/unit/provider/service/systemd_spec.rb +14 -0
  277. data/spec/unit/resource/catalog_spec.rb +12 -2
  278. data/spec/unit/settings/config_file_spec.rb +1 -1
  279. data/spec/unit/transaction/persistence_spec.rb +42 -0
  280. data/spec/unit/transaction/report_spec.rb +19 -4
  281. data/spec/unit/transaction_spec.rb +27 -0
  282. data/spec/unit/type/schedule_spec.rb +14 -0
  283. data/spec/unit/type_spec.rb +3 -3
  284. data/spec/unit/util/errors_spec.rb +1 -1
  285. data/spec/unit/util/http_proxy_spec.rb +37 -0
  286. data/spec/unit/util/log_spec.rb +3 -3
  287. data/spec/unit/util/logging_spec.rb +7 -7
  288. data/spec/unit/util/monkey_patches_spec.rb +6 -2
  289. metadata +3445 -3416
  290. checksums.yaml +0 -7
  291. data/spec/unit/gettext_config_spec.rb +0 -57
@@ -70,7 +70,7 @@
70
70
  #
71
71
  # @example turning a string or array into a hash with index keys
72
72
  #
73
- # ~~puppet
73
+ # ~~~puppet
74
74
  # # Array ['a', 'b', 'c'] to Hash with index results in
75
75
  # # {0 => 'a', 1 => 'b', 2 => 'c'}
76
76
  # Hash(['a', 'b', 'c'].map |$i, $v| { [$i, $v]})
@@ -25,7 +25,7 @@ Puppet::Functions.create_function(:yaml_data) do
25
25
  if data.is_a?(Hash)
26
26
  Puppet::Pops::Lookup::HieraConfig.symkeys_to_string(data)
27
27
  else
28
- Puppet.warning("#{path}: file does not contain a valid yaml hash")
28
+ Puppet.warning(_("%{path}: file does not contain a valid yaml hash" % { path: path }))
29
29
  {}
30
30
  end
31
31
  rescue YAML::SyntaxError => ex
@@ -6,9 +6,10 @@ module Puppet::GettextConfig
6
6
  POSIX_PATH = File.absolute_path('../../../../../share/locale', File.dirname(__FILE__))
7
7
  WINDOWS_PATH = File.absolute_path('../../../../../../../puppet/share/locale', File.dirname(__FILE__))
8
8
 
9
+ DEFAULT_TEXT_DOMAIN = 'default-text-domain'
10
+
9
11
  # Load gettext helpers and track whether they're available.
10
12
  # Used instead of features because we initialize gettext before features is available.
11
- # Stubbing gettext if unavailable is handled in puppet.rb.
12
13
  begin
13
14
  require 'fast_gettext'
14
15
  require 'locale'
@@ -34,33 +35,128 @@ module Puppet::GettextConfig
34
35
  end
35
36
 
36
37
  # @api private
37
- # Whether translations have been loaded for a given project
38
- # @param project_name [String] the project whose translations we are querying
39
- # @return [Boolean] true if translations have been loaded for the project
40
- def self.translations_loaded?(project_name)
41
- return false unless gettext_loaded?
42
- if @loaded_repositories[project_name]
43
- return true
38
+ # Returns the currently selected locale from FastGettext,
39
+ # or 'en' of gettext has not been loaded
40
+ # @return [String] the active locale
41
+ def self.current_locale
42
+ if gettext_loaded?
43
+ return FastGettext.default_locale
44
44
  else
45
- return false
45
+ return 'en'
46
46
  end
47
47
  end
48
48
 
49
49
  # @api private
50
- # Creates a new empty text domain with the given name, replacing
51
- # any existing domain with that name, then switches to using
52
- # that domain. Also clears the cache of loaded translations.
53
- # @param domain_name [String] the name of the domain to create
54
- def self.create_text_domain(domain_name)
55
- return unless gettext_loaded?
56
- # Clear the cache of loaded translation repositories
57
- @loaded_repositories = {}
58
- FastGettext.add_text_domain(domain_name, type: :chain, chain: [])
59
- #TODO remove this when we start managing domains per environment
60
- FastGettext.default_text_domain = domain_name
50
+ # Returns a list of the names of the loaded text domains
51
+ # @return [[String]] the names of the loaded text domains
52
+ def self.loaded_text_domains
53
+ return [] if @gettext_disabled || !gettext_loaded?
54
+
55
+ return FastGettext.translation_repositories.keys
56
+ end
57
+
58
+ # @api private
59
+ # Clears the translation repository for the given text domain,
60
+ # creating it if it doesn't exist, then adds default translations
61
+ # and switches to using this domain.
62
+ # @param [String] domain_name the name of the domain to create
63
+ def self.reset_text_domain(domain_name)
64
+ return if @gettext_disabled || !gettext_loaded?
65
+
66
+ FastGettext.add_text_domain(domain_name,
67
+ type: :chain,
68
+ chain: [],
69
+ report_warning: false)
70
+ copy_default_translations(domain_name)
61
71
  FastGettext.text_domain = domain_name
62
72
  end
63
73
 
74
+ # @api private
75
+ # Creates a default text domain containing the translations for
76
+ # Puppet as the start of chain. When semantic_puppet gets initialized,
77
+ # its translations are added to this chain. This is used as a cache
78
+ # so that all non-module translations only need to be loaded once as
79
+ # we create and reset environment-specific text domains.
80
+ #
81
+ # @return true if Puppet translations were successfully loaded, false
82
+ # otherwise
83
+ def self.create_default_text_domain
84
+ return if @gettext_disabled || !gettext_loaded?
85
+
86
+ FastGettext.add_text_domain(DEFAULT_TEXT_DOMAIN,
87
+ type: :chain,
88
+ chain: [],
89
+ report_warning: false)
90
+ FastGettext.default_text_domain = DEFAULT_TEXT_DOMAIN
91
+
92
+ load_translations('puppet', puppet_locale_path, translation_mode(puppet_locale_path), DEFAULT_TEXT_DOMAIN)
93
+ end
94
+
95
+ # @api private
96
+ # Switches the active text domain, if the requested domain exists.
97
+ # @param [String] domain_name the name of the domain to switch to
98
+ def self.use_text_domain(domain_name)
99
+ return if @gettext_disabled || !gettext_loaded?
100
+
101
+ if FastGettext.translation_repositories.include?(domain_name)
102
+ FastGettext.text_domain = domain_name
103
+ end
104
+ end
105
+
106
+ # @api private
107
+ # Delete all text domains.
108
+ def self.delete_all_text_domains
109
+ FastGettext.translation_repositories.clear
110
+ FastGettext.default_text_domain = nil
111
+ FastGettext.text_domain = nil
112
+ end
113
+
114
+ # @api private
115
+ # Deletes the text domain with the given name
116
+ # @param [String] domain_name the name of the domain to delete
117
+ def self.delete_text_domain(domain_name)
118
+ return if @gettext_disabled || !gettext_loaded?
119
+
120
+ FastGettext.translation_repositories.delete(domain_name)
121
+ if FastGettext.text_domain == domain_name
122
+ FastGettext.text_domain = nil
123
+ end
124
+ end
125
+
126
+ # @api private
127
+ # Deletes all text domains except the default one
128
+ def self.delete_environment_text_domains
129
+ return if @gettext_disabled || !gettext_loaded?
130
+
131
+ FastGettext.translation_repositories.keys.each do |key|
132
+ # do not clear default translations
133
+ next if key == DEFAULT_TEXT_DOMAIN
134
+
135
+ FastGettext.translation_repositories.delete(key)
136
+ end
137
+ FastGettext.text_domain = nil
138
+ end
139
+
140
+ # @api private
141
+ # Adds translations from the default text domain to the specified
142
+ # text domain. Creates the default text domain if one does not exist
143
+ # (this will load Puppet's translations).
144
+ #
145
+ # Since we are currently (Nov 2017) vendoring semantic_puppet, in normal
146
+ # flows these translations will be copied along with Puppet's.
147
+ #
148
+ # @param [String] domain_name the name of the domain to add translations to
149
+ def self.copy_default_translations(domain_name)
150
+ return if @gettext_disabled || !gettext_loaded?
151
+
152
+ if FastGettext.default_text_domain.nil?
153
+ create_default_text_domain
154
+ end
155
+
156
+ puppet_translations = FastGettext.translation_repositories[FastGettext.default_text_domain].chain
157
+ FastGettext.translation_repositories[domain_name].chain.push(*puppet_translations)
158
+ end
159
+
64
160
  # @api private
65
161
  # Search for puppet gettext config files
66
162
  # @return [String] path to the config, or nil if not found
@@ -78,7 +174,7 @@ module Puppet::GettextConfig
78
174
 
79
175
  # @api private
80
176
  # Determine which translation file format to use
81
- # @param conf_path [String] the path to the gettext config file
177
+ # @param [String] conf_path the path to the gettext config file
82
178
  # @return [Symbol] :mo if in a package structure, :po otherwise
83
179
  def self.translation_mode(conf_path)
84
180
  if WINDOWS_PATH == conf_path || POSIX_PATH == conf_path
@@ -96,11 +192,15 @@ module Puppet::GettextConfig
96
192
 
97
193
  # @api private
98
194
  # Attempt to load tranlstions for the given project.
99
- # @param project_name [String] the project whose translations we want to load
100
- # @param locale_dir [String] the path to the directory containing translations
101
- # @param file_format [Symbol] translation file format to use, either :po or :mo
195
+ # @param [String] project_name the project whose translations we want to load
196
+ # @param [String] locale_dir the path to the directory containing translations
197
+ # @param [Symbol] file_format translation file format to use, either :po or :mo
102
198
  # @return true if initialization succeeded, false otherwise
103
- def self.load_translations(project_name, locale_dir, file_format)
199
+ def self.load_translations(project_name, locale_dir, file_format, text_domain = FastGettext.text_domain)
200
+ if project_name.nil? || project_name.empty?
201
+ raise Puppet::Error, "A project name must be specified in order to initialize translations."
202
+ end
203
+
104
204
  return false if @gettext_disabled || !@gettext_loaded
105
205
 
106
206
  return false unless locale_dir && Puppet::FileSystem.exist?(locale_dir)
@@ -109,38 +209,41 @@ module Puppet::GettextConfig
109
209
  raise Puppet::Error, "Unsupported translation file format #{file_format}; please use :po or :mo"
110
210
  end
111
211
 
112
- if project_name.nil? || project_name.empty?
113
- raise Puppet::Error, "A project name must be specified in order to initialize translations."
114
- end
115
-
116
- add_repository_to_domain(project_name, locale_dir, file_format)
212
+ add_repository_to_domain(project_name, locale_dir, file_format, text_domain)
117
213
  return true
118
214
  end
119
215
 
120
216
  # @api private
121
217
  # Add the translations for this project to the domain's repository chain
122
218
  # chain for the currently selected text domain, if needed.
123
- # @param project_name [String] the name of the project for which to load translations
124
- # @param locale_dir [String] the path to the directory containing translations
125
- # @param file_format [Symbol] the fomat of the translations files, :po or :mo
126
- def self.add_repository_to_domain(project_name, locale_dir, file_format)
127
- # check if we've already loaded these transltaions
128
- current_chain = FastGettext.translation_repositories[FastGettext.text_domain].chain
129
- return current_chain if @loaded_repositories[project_name]
219
+ # @param [String] project_name the name of the project for which to load translations
220
+ # @param [String] locale_dir the path to the directory containing translations
221
+ # @param [Symbol] file_format the fomat of the translations files, :po or :mo
222
+ def self.add_repository_to_domain(project_name, locale_dir, file_format, text_domain = FastGettext.text_domain)
223
+ return if @gettext_disabled || !gettext_loaded?
224
+
225
+ current_chain = FastGettext.translation_repositories[text_domain].chain
130
226
 
131
227
  repository = FastGettext::TranslationRepository.build(project_name,
132
228
  path: locale_dir,
133
229
  type: file_format,
134
- ignore_fuzzy: false)
135
- @loaded_repositories[project_name] = true
230
+ report_warning: false)
136
231
  current_chain << repository
137
232
  end
138
233
 
234
+ # @api private
235
+ # Sets FastGettext's locale to the current system locale
236
+ def self.setup_locale
237
+ return if @gettext_disabled || !gettext_loaded?
238
+
239
+ set_locale(Locale.current.language)
240
+ end
241
+
139
242
  # @api private
140
243
  # Sets the language in which to display strings.
141
- # @param locale [String] the language portion of a locale string (e.g. "ja")
244
+ # @param [String] locale the language portion of a locale string (e.g. "ja")
142
245
  def self.set_locale(locale)
143
- return if !gettext_loaded?
246
+ return if @gettext_disabled || !gettext_loaded?
144
247
  # make sure we're not using the `available_locales` machinery
145
248
  FastGettext.default_available_locales = nil
146
249
 
@@ -0,0 +1,42 @@
1
+ require 'puppet/gettext/config'
2
+
3
+ module Puppet::ModuleTranslations
4
+
5
+ # @api private
6
+ # Loads translation files for each of the specified modules,
7
+ # if present. Requires the modules to have `forge_name` specified.
8
+ # @param [[Module]] modules a list of modules for which to
9
+ # load translations
10
+ def self.load_from_modulepath(modules)
11
+ modules.each do |mod|
12
+ next unless mod.forge_name && mod.has_translations?(Puppet::GettextConfig.current_locale)
13
+
14
+ module_name = mod.forge_name.gsub('/', '-')
15
+ if Puppet::GettextConfig.load_translations(module_name, mod.locale_directory, :po)
16
+ Puppet.debug "Loaded translations for #{module_name}."
17
+ elsif Puppet::GettextConfig.gettext_loaded?
18
+ Puppet.debug "Could not find translation files for #{module_name} at #{mod.locale_directory}. Skipping translation initialization."
19
+ else
20
+ Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
21
+ end
22
+ end
23
+ end
24
+
25
+ # @api private
26
+ # Loads translation files that have been pluginsync'd for modules
27
+ # from the $vardir.
28
+ # @param [String] vardir the path to Puppet's vardir
29
+ def self.load_from_vardir(vardir)
30
+ locale = Puppet::GettextConfig.current_locale
31
+ Dir.glob("#{vardir}/locales/#{locale}/*.po") do |f|
32
+ module_name = File.basename(f, ".po")
33
+ if Puppet::GettextConfig.load_translations(module_name, File.join(vardir, "locales"), :po)
34
+ Puppet.debug "Loaded translations for #{module_name}."
35
+ elsif Puppet::GettextConfig.gettext_loaded?
36
+ Puppet.debug "Could not load translations for #{module_name}."
37
+ else
38
+ Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
39
+ end
40
+ end
41
+ end
42
+ end
@@ -70,7 +70,7 @@ class Puppet::Graph::RelationshipGraph < Puppet::Graph::SimpleGraph
70
70
  if @blockers[resource] > 0
71
71
  @blockers[resource] -= 1
72
72
  else
73
- resource.warning "appears to have a negative number of dependencies"
73
+ resource.warning _("appears to have a negative number of dependencies")
74
74
  end
75
75
  @blockers[resource] <= 0
76
76
  end
@@ -229,17 +229,17 @@ class Puppet::Graph::SimpleGraph
229
229
  return if number_of_cycles == 0
230
230
 
231
231
  message = n_("Found %{num} dependency cycle:\n", "Found %{num} dependency cycles:\n", number_of_cycles) % { num: number_of_cycles }
232
+
232
233
  cycles.each do |cycle|
233
234
  paths = paths_in_cycle(cycle)
234
- message += paths.map{ |path| '(' + path.join(" => ") + ')'}.join("\n") + "\n"
235
+ message += paths.map{ |path| '(' + path.join(' => ') + ')'}.join('\n') + '\n'
235
236
  end
236
237
 
237
238
  if Puppet[:graph] then
238
239
  filename = write_cycles_to_graph(cycles)
239
240
  message += _("Cycle graph written to %{filename}.") % { filename: filename }
240
241
  else
241
- #TRANSLATORS "graph" refers to a command line option and should not be translated
242
- #TRANSLATORS OmniGraffle and GraphViz and program names and should not be translated
242
+ #TRANSLATORS '--graph' refers to a command line option and OmniGraffle and GraphViz are program names and should not be translated
243
243
  message += _("Try the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz")
244
244
  end
245
245
  Puppet.err(message)
@@ -49,6 +49,8 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
49
49
  node = node_from_request(facts, request)
50
50
  node.trusted_data = Puppet.lookup(:trusted_information) { Puppet::Context::TrustedInformation.local(node) }.to_h
51
51
 
52
+ node.environment.use_text_domain if node.environment
53
+
52
54
  if catalog = compile(node, request.options)
53
55
  return catalog
54
56
  else
@@ -89,7 +91,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
89
91
  elsif format == 'application/json'
90
92
  return Puppet::Node::Facts.convert_from('json', CGI.unescape(facts))
91
93
  else
92
- raise ArgumentError, "Unsupported facts format"
94
+ raise ArgumentError, _("Unsupported facts format")
93
95
  end
94
96
  end
95
97
 
@@ -275,24 +277,31 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
275
277
  raise Puppet::Error, _("Unable to find a common checksum type between agent '%{agent_type}' and master '%{master_type}'.") % { agent_type: options[:checksum_type], master_type: known_checksum_types } unless checksum_type
276
278
  end
277
279
 
278
- str = if checksum_type
279
- if node.environment
280
- _("Compiled static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
281
- else
282
- _("Compiled static catalog for %{node}") % { node: node.name }
283
- end
284
- else
285
- if node.environment
286
- _("Compiled catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
287
- else
288
- _("Compiled catalog for %{node}") % { node: node.name }
289
- end
290
- end
280
+ escaped_node_name = node.name.gsub(/%/, '%%')
281
+ if checksum_type
282
+ if node.environment
283
+ escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
284
+ benchmark_str = _("Compiled static catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
285
+ profile_str = _("Compiled static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
286
+ else
287
+ benchmark_str = _("Compiled static catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
288
+ profile_str = _("Compiled static catalog for %{node}") % { node: node.name }
289
+ end
290
+ else
291
+ if node.environment
292
+ escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
293
+ benchmark_str = _("Compiled catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
294
+ profile_str = _("Compiled catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
295
+ else
296
+ benchmark_str = _("Compiled catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
297
+ profile_str = _("Compiled catalog for %{node}") % { node: node.name }
298
+ end
299
+ end
291
300
  config = nil
292
301
 
293
- benchmark(:notice, str) do
302
+ benchmark(:notice, benchmark_str) do
294
303
  compile_type = checksum_type ? :static_compile : :compile
295
- Puppet::Util::Profiler.profile(str, [:compiler, compile_type, node.environment, node.name]) do
304
+ Puppet::Util::Profiler.profile(profile_str, [:compiler, compile_type, node.environment, node.name]) do
296
305
  begin
297
306
  config = Puppet::Parser::Compiler.compile(node, options[:code_id])
298
307
  rescue Puppet::Error => detail
@@ -303,15 +312,21 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
303
312
  end
304
313
 
305
314
  if checksum_type && config.is_a?(model)
306
- str = if node.environment
307
- #TRANSLATORS Inlined refers to adding additional metadata
308
- _("Inlined resource metadata into static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
309
- else
310
- #TRANSLATORS Inlined refers to adding additional metadata
311
- _("Inlined resource metadata into static catalog for %{node}") % { node: node.name }
312
- end
313
- benchmark(:notice, str) do
314
- Puppet::Util::Profiler.profile(str, [:compiler, :static_compile_postprocessing, node.environment, node.name]) do
315
+ escaped_node_name = node.name.gsub(/%/, '%%')
316
+ if node.environment
317
+ escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
318
+ #TRANSLATORS Inlined refers to adding additional metadata
319
+ benchmark_str = _("Inlined resource metadata into static catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
320
+ #TRANSLATORS Inlined refers to adding additional metadata
321
+ profile_str = _("Inlined resource metadata into static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
322
+ else
323
+ #TRANSLATORS Inlined refers to adding additional metadata
324
+ benchmark_str = _("Inlined resource metadata into static catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
325
+ #TRANSLATORS Inlined refers to adding additional metadata
326
+ profile_str = _("Inlined resource metadata into static catalog for %{node}") % { node: node.name }
327
+ end
328
+ benchmark(:notice, benchmark_str) do
329
+ Puppet::Util::Profiler.profile(profile_str, [:compiler, :static_compile_postprocessing, node.environment, node.name]) do
315
330
  inline_metadata(config, checksum_type)
316
331
  end
317
332
  end
@@ -8,7 +8,7 @@ class Puppet::Indirector::Exec < Puppet::Indirector::Terminus
8
8
  external_command = command
9
9
 
10
10
  # Make sure it's an array
11
- raise Puppet::DevError, "Exec commands must be an array" unless external_command.is_a?(Array)
11
+ raise Puppet::DevError, _("Exec commands must be an array") unless external_command.is_a?(Array)
12
12
 
13
13
  # Make sure it's fully qualified.
14
14
  raise ArgumentError, _("You must set the exec parameter to a fully qualified command") unless Puppet::Util.absolute_path?(external_command[0])
@@ -11,11 +11,11 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
11
11
  end
12
12
 
13
13
  def destroy(facts)
14
- raise Puppet::DevError, 'You cannot destroy facts in the code store; it is only used for getting facts from Facter'
14
+ raise Puppet::DevError, _('You cannot destroy facts in the code store; it is only used for getting facts from Facter')
15
15
  end
16
16
 
17
17
  def save(facts)
18
- raise Puppet::DevError, 'You cannot save facts to the code store; it is only used for getting facts from Facter'
18
+ raise Puppet::DevError, _('You cannot save facts to the code store; it is only used for getting facts from Facter')
19
19
  end
20
20
 
21
21
  # Lookup a host's facts up in Facter.
@@ -55,7 +55,7 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
55
55
  # print out each .rb in the facts directory as module
56
56
  # developers may find that information useful for debugging purposes
57
57
  if Puppet::Util::Log.sendlevel?(:info)
58
- Puppet.info "Loading facts"
58
+ Puppet.info _("Loading facts")
59
59
  Dir.glob("#{dir}/*.rb").each do |file|
60
60
  Puppet.debug "Loading facts from #{file}"
61
61
  end