Skip to content

Commit

Permalink
Setup translation infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren authored and chris1984 committed Jul 13, 2023
1 parent 43d0639 commit 6c66472
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 85 deletions.
3 changes: 1 addition & 2 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ file_filter = locale/<lang>/hammer-cli-katello.edit.po
source_file = locale/hammer-cli-katello.pot
source_lang = en
type = PO
minimum_perc = 0
resource_name = hammer-cli-katello
resource_name = hammer-cli-katello
29 changes: 7 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,10 @@ task :default do
Rake::Task['test'].execute
end

namespace :gettext do
task :setup do
require "hammer_cli_katello/version"
require "hammer_cli_katello/i18n"
require 'gettext/tools/task'

domain = HammerCLIKatello::I18n::LocaleDomain.new
GetText::Tools::Task.define do |task|
task.package_name = domain.domain_name
task.package_version = HammerCLIKatello.version.to_s
task.domain = domain.domain_name
task.mo_base_directory = domain.locale_dir
task.po_base_directory = domain.locale_dir
task.files = domain.translated_files
end
end

desc "Update pot file"
task :find => [:setup] do
Rake::Task["gettext:po:update"].invoke
end
end
require "hammer_cli_katello/version"
require "hammer_cli_katello/i18n"
require "hammer_cli/i18n/find_task"
HammerCLI::I18n::FindTask.define(
HammerCLIKatello::I18n::LocaleDomain.new,
HammerCLIKatello.version.to_s
)
63 changes: 2 additions & 61 deletions locale/Makefile
Original file line number Diff line number Diff line change
@@ -1,65 +1,6 @@
#
# 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
# Run make help to list available targets
#
DOMAIN = hammer-cli-katello
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load("../hammer_cli_katello.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!
include $(shell bundle exec ruby -e 'require "hammer_cli"; puts HammerCLI::I18n.main_makefile')

0 comments on commit 6c66472

Please sign in to comment.