Project

General

Profile

« Previous | Next » 

Revision 50ad777d

Added by Bryan Kearney over 9 years ago

Plugins should support i18n. This commit adds the basics, but the engineers need to start translating code

View differences:

Gemfile
# 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)
Rakefile
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
hammer_cli_csv.gemspec
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
lib/hammer_cli_csv/i18n.rb
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)
locale/Makefile
#
# 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!
locale/README.md
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.
locale/hammer_cli_csv.pot
# 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 <LL@li.org>\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 ""

Also available in: Unified diff