Skip to content

Commit

Permalink
Plugins should support i18n. This commit adds the basics, but the eng…
Browse files Browse the repository at this point in the history
…ineers need to start translating code
  • Loading branch information
bkearney committed Feb 16, 2015
1 parent e76f156 commit 50ad777
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ end

# load local gemfile
local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ rescue
puts "Rubocop not loaded"
end

namespace :gettext do
desc "Update pot file"
task :find do
require "hammer_cli_csv/version"
require "hammer_cli_csv/i18n"
require 'gettext/tools'

domain = HammerCLICsv::I18n::LocaleDomain.new
GetText.update_pofiles(domain.domain_name, domain.translated_files, "#{domain.domain_name} #{HammerCLICsv.version}", :po_root => domain.locale_dir)
end
end


task :default do
Rake::Task['rubocop'].execute
end
2 changes: 1 addition & 1 deletion hammer_cli_csv.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.require_paths = %w(lib)

spec.add_dependency('hammer_cli_katello')

spec.add_dependency("gettext", "~> 2.0")
spec.add_development_dependency("rubocop", "0.24.1")

end
24 changes: 24 additions & 0 deletions lib/hammer_cli_csv/i18n.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'hammer_cli/i18n'

module HammerCLICsv
module I18n

class LocaleDomain < HammerCLI::I18n::LocaleDomain

def translated_files
Dir.glob(File.join(File.dirname(__FILE__), '../**/*.rb'))
end

def locale_dir
File.join(File.dirname(__FILE__), '../../locale')
end

def domain_name
'hammer_cli_csv'
end
end

end
end

HammerCLI::I18n.add_domain(HammerCLICsv::I18n::LocaleDomain.new)
65 changes: 65 additions & 0 deletions locale/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Makefile for PO merging and MO generation. More info in the README.
#
# make all-mo (default) - generate MO files
# make check - check translations using translate-tool
# make tx-update - download and merge translations from Transifex
# make clean - clean everything
#
DOMAIN = hammer_cli_csv
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load("../hammer_cli_csv.gemspec");puts spec.version')
POTFILE = $(DOMAIN).pot
MOFILE = $(DOMAIN).mo
POFILES = $(shell find . -name '*.po')
MOFILES = $(patsubst %.po,%.mo,$(POFILES))
POXFILES = $(patsubst %.po,%.pox,$(POFILES))

%.mo: %.po
mkdir -p $(shell dirname $@)/LC_MESSAGES
msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<

# Generate MO files from PO files
all-mo: $(MOFILES)

# Check for malformed strings
%.pox: %.po
msgfmt -c $<
pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
-t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
cat $@
! grep -q msgid $@

check: $(POXFILES)
msgfmt -c ${POTFILE}

# Merge PO files
update-po:
for f in $(shell find ./ -name "*.po") ; do \
msgmerge -N --backup=none -U $$f ${POTFILE} ; \
done

# Unify duplicate translations
uniq-po:
for f in $(shell find ./ -name "*.po") ; do \
msguniq $$f -o $$f ; \
done

tx-pull:
tx pull -f
for f in $(POFILES) ; do \
sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
done
-git commit -a -m "i18n - extracting new, pulling from tx"

extract-strings:
bundle exec rake gettext:find

reset-po:
# merging po files is unnecessary when using transifex.com
git checkout -- ../locale/*/*po

tx-update: tx-pull extract-strings reset-po $(MOFILES)
# amend mo files
git add ../locale/*/LC_MESSAGES
git commit -a --amend -m "i18n - extracting new, pulling from tx"
-echo Changes commited!
18 changes: 18 additions & 0 deletions locale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Updating the translations
-------------------------

1. Check if there are any new languages with progress more than 50% on [transifex](https://www.transifex.com/projects/p/foreman/resource/hammer-cli-csv/). If so, do the following for each of the new languages:

```
mkdir locale/<lang>
cp locale/hammer_cli_csv.pot locale/<lang>/hammer_cli_csv.po
```
2. Make sure you have `transifex-client` installed

3. Update the translations. From GIT repo root directory run:

```
make -C locale tx-update
```

It will download translations from transifex, generates `mo` files, updates strings in `pot` file and wraps all the changes in a new commit. Transifex automatically updates its strings when the commit is pushed to Github.
23 changes: 23 additions & 0 deletions locale/hammer_cli_csv.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: hammer_cli_csv 0.0.6\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-15 12:46-0500\n"
"PO-Revision-Date: 2015-02-15 12:46-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: lib/hammer_cli_csv/csv.rb:21
msgid "import to, or export from a running foretello server"
msgstr ""

0 comments on commit 50ad777

Please sign in to comment.