Skip to content

Commit

Permalink
(CONT-370) Remove i18n support
Browse files Browse the repository at this point in the history
This commit removes i18n support from PDK as it is no longer required.

Additionally we have also seen a small performance improvement as a
result of this work.
  • Loading branch information
chelnak committed Feb 16, 2023
1 parent c7c851a commit 7e31ec2
Show file tree
Hide file tree
Showing 114 changed files with 648 additions and 2,872 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Environment Variable | Usage
1. Bump the version in `lib/pdk/version.rb`.
1. In a clean checkout of main, run `bundle exec rake changelog`.
1. Edit PR titles and tags, until `bundle exec rake changelog` output makes sense.
1. Run `bundle exec rake gettext:pot` to update the translations.
1. Commit and PR the changes.
1. When the PR is merged, get a clean checkout of the merged commit, and run `bundle exec rake release[upstream]` (where "upstream" is your local name of the puppetlabs remote)
1. Profit!
Expand Down
22 changes: 0 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ require 'puppetlabs_spec_helper/tasks/fixtures' if Bundler.rubygems.find_name('p
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

gettext_spec = Gem::Specification.find_by_name 'gettext-setup'
load "#{gettext_spec.gem_dir}/lib/tasks/gettext.rake"
GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))

build_defs_file = 'ext/build_defaults.yaml'
if File.exist?(build_defs_file)
begin
Expand Down Expand Up @@ -85,24 +81,6 @@ end

task default: :spec

namespace :gettext do
desc 'Remove obsolete messages from translations'
task(:clean_obsolete, [:language]) do |_task, args|
file_name = File.join(File.dirname(__FILE__), 'locales', args[:language], 'pdk.po')
success = system("msgattrib --no-obsolete #{file_name} -o #{file_name}")

puts "Updated #{file_name}" if success
end

desc 'Remove fuzzy messages from translations (should only be used by translators of this language)'
task(:clean_fuzzy, [:language]) do |_task, args|
file_name = File.join(File.dirname(__FILE__), 'locales', args[:language], 'pdk.po')
success = system("msgattrib --clear-fuzzy #{file_name} -o #{file_name}")

puts "Updated #{file_name}" if success
end
end

begin
require 'github_changelog_generator/task'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
Expand Down
2 changes: 0 additions & 2 deletions lib/pdk.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'pdk/i18n'

module PDK
autoload :Analytics, 'pdk/analytics'
autoload :AnswerFile, 'pdk/answer_file'
Expand Down
6 changes: 4 additions & 2 deletions lib/pdk/analytics/client/google_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(opts)

def screen_view(screen, **kwargs)
custom_dimensions = walk_keys(kwargs) do |k|
CUSTOM_DIMENSIONS[k] || raise(_("Unknown analytics key '%{key}'") % { key: k })
CUSTOM_DIMENSIONS[k] || raise("Unknown analytics key '%{key}'" % { key: k })
end

screen_view_params = {
Expand All @@ -57,7 +57,7 @@ def screen_view(screen, **kwargs)

def event(category, action, label: nil, value: nil, **kwargs)
custom_dimensions = walk_keys(kwargs) do |k|
CUSTOM_DIMENSIONS[k] || raise(_("Unknown analytics key '%{key}'") % { key: k })
CUSTOM_DIMENSIONS[k] || raise("Unknown analytics key '%{key}'" % { key: k })
end

event_params = {
Expand Down Expand Up @@ -92,6 +92,8 @@ def submit(params)
# These parameters have terrible names. See this page for complete documentation:
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
def base_params
require 'locale'

{
v: PROTOCOL_VERSION,
# Client ID
Expand Down
60 changes: 29 additions & 31 deletions lib/pdk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,21 @@ def self.anonymised_args
end
end

def self.deprecated_runtime?
Gem::Version.new(RbConfig::CONFIG['ruby_version']) < Gem::Version.new('2.4.0')
end
# def self.deprecated_runtime?
# Gem::Version.new(RbConfig::CONFIG['ruby_version']) < Gem::Version.new('2.4.0')
# end

def self.run(args)
if deprecated_runtime?
PDK.logger.info(
text: _(
'Support for Ruby versions older than 2.4 will be dropped in the ' \
'future PDK 2.0.0 release. We recommend updating your Ruby ' \
'installation to ensure that you can continue using the latest ' \
'version of PDK.',
),
wrap: true,
)
end
# if deprecated_runtime?
# PDK.logger.info(
# text:
# 'Support for Ruby versions older than 2.4 will be dropped in the ' \
# 'future PDK 2.0.0 release. We recommend updating your Ruby ' \
# 'installation to ensure that you can continue using the latest ' \
# 'version of PDK.',F
# wrap: true,
# )
# end

@args = args
PDK::Config.analytics_config_interview! unless PDK::Util::Env['PDK_DISABLE_ANALYTICS'] || PDK::Config.analytics_config_exist?
Expand Down Expand Up @@ -94,63 +93,62 @@ def self.run(args)
def self.template_url_option(dsl)
require 'pdk/util/template_uri'

desc = _('Specifies the URL to the template to use when creating new modules or classes. (default: %{default_url})') % { default_url: PDK::Util::TemplateURI.default_template_uri }
desc = 'Specifies the URL to the template to use when creating new modules or classes. (default: %{default_url})' % { default_url: PDK::Util::TemplateURI.default_template_uri }

dsl.option nil, 'template-url', desc, argument: :required
end

def self.template_ref_option(dsl)
dsl.option nil, 'template-ref', _('Specifies the template git branch or tag to use when creating new modules or classes.'), argument: :required
dsl.option nil, 'template-ref', 'Specifies the template git branch or tag to use when creating new modules or classes.', argument: :required
end

def self.skip_interview_option(dsl)
dsl.option nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
dsl.option nil, 'skip-interview', 'When specified, skips interactive querying of metadata.'
end

def self.full_interview_option(dsl)
dsl.option nil, 'full-interview', _('When specified, interactive querying of metadata will include all optional questions.')
dsl.option nil, 'full-interview', 'When specified, interactive querying of metadata will include all optional questions.'
end

def self.puppet_version_options(dsl)
dsl.option nil, 'puppet-version', _('Puppet version to run tests or validations against.'), argument: :required
dsl.option nil, 'pe-version', _('Puppet Enterprise version to run tests or validations against.'), argument: :required
dsl.option nil, 'puppet-version', 'Puppet version to run tests or validations against.', argument: :required
dsl.option nil, 'pe-version', 'Puppet Enterprise version to run tests or validations against.', argument: :required
end

def self.puppet_dev_option(dsl)
dsl.option nil,
'puppet-dev',
_('When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.')
'When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.'
end

@base_cmd = Cri::Command.define do
name 'pdk'
usage _('pdk command [options]')
summary _('Puppet Development Kit')
description _('The shortest path to better modules.')
usage 'pdk command [options]'
summary 'Puppet Development Kit'
description 'The shortest path to better modules.'
default_subcommand 'help'

flag nil, :version, _('Show version of pdk.') do |_, _|
flag nil, :version, 'Show version of pdk.' do |_, _|
puts PDK::Util::Version.version_string
exit 0
end

flag :h, :help, _('Show help for this command.') do |_, c|
flag :h, :help, 'Show help for this command.' do |_, c|
puts c.help
exit 0
end

format_desc = _(
"Specify desired output format. Valid formats are '%{available_formats}'. " \
format_desc =
"Specify desired output format. Valid formats are '#{PDK::Report.formats.join("', '")}'. " \
'You may also specify a file to which the formatted output is sent, ' \
"for example: '--format=junit:report.xml'. This option may be specified " \
'multiple times if each option specifies a distinct target file.',
) % { available_formats: PDK::Report.formats.join("', '") }
'multiple times if each option specifies a distinct target file.'

option :f, :format, format_desc, argument: :required, multiple: true do |values|
PDK::CLI::Util::OptionNormalizer.report_formats(values.compact)
end

flag :d, :debug, _('Enable debug output.') do |_, _|
flag :d, :debug, 'Enable debug output.' do |_, _|
PDK.logger.enable_debug_output
end
end
Expand Down
38 changes: 17 additions & 21 deletions lib/pdk/cli/build.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module PDK::CLI
@build_cmd = @base_cmd.define_command do
name 'build'
usage _('build [options]')
summary _('Builds a package from the module that can be published to the Puppet Forge.')
usage 'build [options]'
summary 'Builds a package from the module that can be published to the Puppet Forge.'

option nil, 'target-dir',
_('The target directory where you want PDK to write the package.'),
'The target directory where you want PDK to write the package.',
argument: :required, default: File.join(Dir.pwd, 'pkg')

option nil, 'force', _('Skips the prompts and builds the module package.')
option nil, 'force', 'Skips the prompts and builds the module package.'

run do |opts, _args, _cmd|
require 'pdk/module/build'
Expand All @@ -17,7 +17,7 @@ module PDK::CLI

# Make sure build is being run in a valid module directory with a metadata.json
PDK::CLI::Util.ensure_in_module!(
message: _('`pdk build` can only be run from inside a valid module with a metadata.json.'),
message: '`pdk build` can only be run from inside a valid module with a metadata.json.',
log_level: :info,
)

Expand All @@ -30,12 +30,8 @@ module PDK::CLI
#
unless module_metadata.forge_ready?
if opts[:force]
PDK.logger.warn _(
'This module is missing the following fields in the metadata.json: %{fields}. ' \
'These missing fields may affect the visibility of the module on the Forge.',
) % {
fields: module_metadata.missing_fields.join(', '),
}
PDK.logger.warn "This module is missing the following fields in the metadata.json: #{module_metadata.missing_fields.join(', ')}. " \
'These missing fields may affect the visibility of the module on the Forge.'
else
module_metadata.interview_for_forge!
module_metadata.write!('metadata.json')
Expand All @@ -46,34 +42,34 @@ module PDK::CLI

unless opts[:force]
if builder.package_already_exists?
PDK.logger.info _("The file '%{package}' already exists.") % { package: builder.package_file }
PDK.logger.info "The file '%{package}' already exists." % { package: builder.package_file }

unless PDK::CLI::Util.prompt_for_yes(_('Overwrite?'), default: false)
PDK.logger.info _('Build cancelled; exiting.')
unless PDK::CLI::Util.prompt_for_yes('Overwrite?', default: false)
PDK.logger.info 'Build cancelled; exiting.'
exit 0
end
end

unless builder.module_pdk_compatible?
PDK.logger.info _('This module is not compatible with PDK, so PDK can not validate or test this build. ' \
'Unvalidated modules may have errors when uploading to the Forge. ' \
'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.')
PDK.logger.info 'This module is not compatible with PDK, so PDK can not validate or test this build. ' \
'Unvalidated modules may have errors when uploading to the Forge. ' \
'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'

unless PDK::CLI::Util.prompt_for_yes(_('Continue build without converting?'))
PDK.logger.info _('Build cancelled; exiting.')
unless PDK::CLI::Util.prompt_for_yes('Continue build without converting?')
PDK.logger.info 'Build cancelled; exiting.'
exit 0
end
end
end

PDK.logger.info _('Building %{module_name} version %{module_version}') % {
PDK.logger.info 'Building %{module_name} version %{module_version}' % {
module_name: module_metadata.data['name'],
module_version: module_metadata.data['version'],
}

builder.build

PDK.logger.info _('Build of %{package_name} has completed successfully. Built package can be found here: %{package_path}') % {
PDK.logger.info 'Build of %{package_name} has completed successfully. Built package can be found here: %{package_path}' % {
package_name: module_metadata.data['name'],
package_path: builder.package_file,
}
Expand Down
9 changes: 4 additions & 5 deletions lib/pdk/cli/bundle.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
module PDK::CLI
@bundle_cmd = @base_cmd.define_command do
name 'bundle'
usage _('bundle [bundler_options]')
summary _('(Experimental) Command pass-through to bundler')
description _(<<-EOF
usage 'bundle [bundler_options]'
summary '(Experimental) Command pass-through to bundler'
description <<-EOF
[experimental] For advanced users, pdk bundle runs arbitrary commands in the bundler environment that pdk manages.
Careless use of this command can lead to errors that pdk can't help recover from.
EOF
)
skip_option_parsing

run do |_opts, args, _cmd|
require 'pdk/cli/exec/interactive_command'
require 'pdk/util/bundler'

PDK::CLI::Util.ensure_in_module!(
message: _('`pdk bundle` can only be run from inside a valid module directory.'),
message: '`pdk bundle` can only be run from inside a valid module directory.',
)

PDK::CLI::Util.validate_puppet_version_opts({})
Expand Down
6 changes: 3 additions & 3 deletions lib/pdk/cli/config.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module PDK::CLI
@config_cmd = @base_cmd.define_command do
name 'config'
usage _('config [subcommand] [options]')
summary _('(Deprecated) Configure the Puppet Development Kit.')
usage 'config [subcommand] [options]'
summary '(Deprecated) Configure the Puppet Development Kit.'
default_subcommand 'help'

run do |_opts, args, _cmd|
PDK.logger.warn _('The \'pdk config\' command is deprecated, please use \'pdk get config\' and \'pdk set config\' instead.')
PDK.logger.warn 'The \'pdk config\' command is deprecated, please use \'pdk get config\' and \'pdk set config\' instead.'

if args == ['help']
PDK::CLI.run(%w[config --help])
Expand Down
12 changes: 6 additions & 6 deletions lib/pdk/cli/config/get.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module PDK::CLI
@config_get_cmd = @config_cmd.define_command do
name 'get'
usage _('config get [name]')
summary _('(Deprecated) Retrieve the configuration for <name>. If not specified, retrieve all configuration settings')
usage 'config get [name]'
summary '(Deprecated) Retrieve the configuration for <name>. If not specified, retrieve all configuration settings'

run do |_opts, args, _cmd|
PDK.logger.warn _('The \'pdk config get\' command is deprecated, please use \'pdk get config\' instead.')
PDK.logger.warn 'The \'pdk config get\' command is deprecated, please use \'pdk get config\' instead.'

item_name = args[0]
resolved_config = PDK.config.resolve(item_name)
# If the user wanted to know a setting but it doesn't exist, raise an error
if resolved_config.empty? && !item_name.nil?
PDK.logger.error(_("Configuration item '%{name}' does not exist") % { name: item_name })
PDK.logger.error("Configuration item '%{name}' does not exist" % { name: item_name })
exit 1
end
# If the user requested a setting and it's the only one resolved, then just output the value
if resolved_config.count == 1 && resolved_config.keys[0] == item_name
puts _('%{value}') % { value: resolved_config.values[0] }
puts '%{value}' % { value: resolved_config.values[0] }
exit 0
end
# Otherwise just output everything
resolved_config.keys.sort.each { |key| puts _('%{name}=%{value}') % { name: key, value: resolved_config[key] } }
resolved_config.keys.sort.each { |key| puts '%{name}=%{value}' % { name: key, value: resolved_config[key] } }
end
end
end
Loading

0 comments on commit 7e31ec2

Please sign in to comment.