Skip to content

Commit fc0436d

Browse files
authored
Merge pull request #8704 from joshcooper/l10n_test
(maint) Add l10n integration test
2 parents 9e32544 + 40062d0 commit fc0436d

File tree

9 files changed

+151
-0
lines changed

9 files changed

+151
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source ENV['GEM_SOURCE'] || "https://rubygems.org"
2+
3+
gem 'gettext-setup', '~> 0.28', require: false, platforms: [:ruby]
4+
gem "rake"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spec = Gem::Specification.find_by_name 'gettext-setup'
2+
load "#{spec.gem_dir}/lib/tasks/gettext.rake"
3+
GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Puppet::Functions.create_function(:l10n) do
2+
dispatch :l10n_impl do
3+
end
4+
5+
def l10n_impl
6+
_("IT'S HAPPY FUN TIME")
7+
end
8+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# This is the project-specific configuration file for setting up
3+
# fast_gettext for your project.
4+
gettext:
5+
# This is used for the name of the .pot and .po files; they will be
6+
# called <project_name>.pot?
7+
project_name: 'puppet-l10n'
8+
# This is used in comments in the .pot and .po files to indicate what
9+
# project the files belong to and should bea little more descriptive than
10+
# <project_name>
11+
package_name: puppet l10n demo
12+
# The locale that the default messages in the .pot file are in
13+
default_locale: en
14+
# The email used for sending bug reports.
15+
bugs_address: docs@puppetlabs.com
16+
# The holder of the copyright.
17+
copyright_holder: Puppet Labs, LLC.
18+
# This determines which comments in code should be eligible for translation.
19+
# Any comments that start with this string will be externalized. (Leave
20+
# empty to include all.)
21+
comments_tag: TRANSLATORS
22+
# Patterns for +Dir.glob+ used to find all files that might contain
23+
# translatable content, relative to the project root directory
24+
source_files:
25+
- 'lib/**/*.rb'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Puppet, 2021
2+
#
3+
msgid ""
4+
msgstr ""
5+
"Project-Id-Version: 1.0\n"
6+
"Report-Msgid-Bugs-To: \n"
7+
"POT-Creation-Date: 2018-03-29 12:41+0000\n"
8+
"PO-Revision-Date: 2018-03-29 12:43+0000\n"
9+
"Last-Translator: Puppet\n"
10+
"Language-Team: English\n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: 8bit\n"
14+
"Language: en\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
17+
#: ../lib/puppet/functions/l10n.rb:5
18+
msgid "IT'S HAPPY FUN TIME"
19+
msgstr "それは楽しい時間です"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) 2021 Puppet Labs, LLC.
3+
# This file is distributed under the same license as the puppet l10n demo package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2021.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: puppet l10n demo 6.23.0-100-gdc4e95bd86\n"
10+
"\n"
11+
"Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12+
"POT-Creation-Date: 2021-07-16 16:48-0700\n"
13+
"PO-Revision-Date: 2021-07-16 16:48-0700\n"
14+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15+
"Language-Team: LANGUAGE <LL@li.org>\n"
16+
"Language: \n"
17+
"MIME-Version: 1.0\n"
18+
"Content-Type: text/plain; charset=UTF-8\n"
19+
"Content-Transfer-Encoding: 8bit\n"
20+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "puppet-l10n",
3+
"version": "0.0.1",
4+
"author": "puppet",
5+
"source": "",
6+
"license": "Apache-2.0",
7+
"dependencies": []
8+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'spec_helper'
2+
3+
describe 'compiler localization' do
4+
include_context 'l10n', 'ja'
5+
6+
let(:envdir) { File.join(my_fixture_dir, '..', 'envs') }
7+
let(:environments) do
8+
Puppet::Environments::Cached.new(
9+
Puppet::Environments::Directories.new(envdir, [])
10+
)
11+
end
12+
let(:env) { Puppet::Node::Environment.create(:prod, [File.join(envdir, 'prod', 'modules')]) }
13+
let(:node) { Puppet::Node.new('test', :environment => env) }
14+
15+
around(:each) do |example|
16+
Puppet.override(current_environment: env,
17+
loaders: Puppet::Pops::Loaders.new(env),
18+
environments: environments) do
19+
example.run
20+
end
21+
end
22+
23+
it 'localizes strings in functions' do
24+
Puppet[:code] = <<~END
25+
notify { 'demo':
26+
message => l10n()
27+
}
28+
END
29+
30+
Puppet::Resource::Catalog.indirection.terminus_class = :compiler
31+
catalog = Puppet::Resource::Catalog.indirection.find(node.name)
32+
resource = catalog.resource(:notify, 'demo')
33+
34+
expect(resource).to be
35+
expect(resource[:message]).to eq("それは楽しい時間です")
36+
end
37+
end

spec/shared_contexts/l10n.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'spec_helper'
2+
3+
RSpec.shared_context('l10n') do |locale|
4+
before :all do
5+
@old_locale = Locale.current
6+
Locale.current = locale
7+
Puppet::GettextConfig.setup_locale
8+
9+
# overwrite stubs with real implementation
10+
::Object.send(:remove_method, :_)
11+
::Object.send(:remove_method, :n_)
12+
class ::Object
13+
include FastGettext::Translation
14+
end
15+
end
16+
17+
after :all do
18+
Locale.current = @old_locale
19+
20+
# restore stubs
21+
load File.expand_path(File.join(__dir__, '../../lib/puppet/gettext/stubs.rb'))
22+
end
23+
24+
before :each do
25+
Puppet[:disable_i18n] = false
26+
end
27+
end

0 commit comments

Comments
 (0)