From 4c61c6275da6d8ef3e82fb832315143b6fda257e Mon Sep 17 00:00:00 2001
From: Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
Date: Tue, 29 Oct 2024 15:09:26 +0100
Subject: [PATCH] Sync translation infrastructure from foreman_plugin_template

This copies the Makefile from foreman_plugin_template to resolve an
issue with the time stamp handling and pulling in new translations that
made it past 50%.

It also ignores action_names.rb since that's now considered a best
practice. Generated files do not belong in git.
---
 .gitignore             |   1 +
 locale/Makefile        |  44 +++++-----
 locale/action_names.rb | 181 -----------------------------------------
 3 files changed, 21 insertions(+), 205 deletions(-)
 delete mode 100644 locale/action_names.rb

diff --git a/.gitignore b/.gitignore
index 63493844a8c..b418ed9d5b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ locale/*/*.po.time_stamp
 locale/.cache/*
 locale/*/*.pox
 locale/*/LC_MESSAGES
+locale/action_names.rb
 .yardoc
 yardoc
 doc/apidoc*
diff --git a/locale/Makefile b/locale/Makefile
index 12660d09969..3102bb3e2ad 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -6,20 +6,19 @@
 # make tx-update - download and merge translations from Transifex
 # make clean - clean everything
 #
-DOMAIN = katello
-VERSION = $(shell git describe --abbrev=0 --tags)
+DOMAIN = $(shell ruby -rrubygems -e 'puts Gem::Specification::load(Dir.glob("../*.gemspec")[0]).name')
+VERSION = $(shell ruby -rrubygems -e 'puts Gem::Specification::load(Dir.glob("../*.gemspec")[0]).version')
 POTFILE = $(DOMAIN).pot
 MOFILE = $(DOMAIN).mo
-ACTIONFILE = action_names.rb
 POFILES = $(shell find . -name '$(DOMAIN).po')
 MOFILES = $(patsubst %.po,%.mo,$(POFILES))
 POXFILES = $(patsubst %.po,%.pox,$(POFILES))
 EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
+JSFILES = $(shell find ../app/assets/javascripts/*/locale -name '$(DOMAIN).js')
 
 %.mo: %.po
 	mkdir -p $(shell dirname $@)/LC_MESSAGES
 	msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
-	touch $(shell dirname $@)/LC_MESSAGES/$(MOFILE)
 
 # Generate MO files from PO files
 all-mo: $(MOFILES)
@@ -32,9 +31,16 @@ all-mo: $(MOFILES)
 	cat $@
 	! grep -q msgid $@
 
-%.edit.po:
+%.edit.po: %.po.time_stamp
 	touch $@
 
+# gettext will trash the .edit.po file if the time stamp doesn't exist or is older than the po file
+%.po.time_stamp: %.po
+	touch --reference $< $@
+
+# Prevent make from treating this as an intermediate file to be cleaned up
+.PRECIOUS: %.po.time_stamp
+
 check: $(POXFILES)
 
 # Unify duplicate translations
@@ -44,34 +50,24 @@ uniq-po:
 	done
 
 tx-pull: $(EDITFILES)
-	tx pull -f
+	# Initialize new languages
+	cd .. && tx pull -f --all --minimum-perc 50
+	# Force update all existing languages
+	cd .. && tx pull -f --minimum-perc 0
 	for f in $(EDITFILES) ; do \
 		sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
 	done
 
 tx-update: tx-pull
 	@echo
-	@echo Run rake plugin:gettext[$(DOMAIN)] and rake plugin:po_to_json[$(DOMAIN)] from the Foreman installation, then make -C locale po-files to finish
+	@echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation
+	@echo then run rake plugin:po_to_json[$(DOMAIN)] from the Foreman installation
+	@echo then run make -C locale mo-files to finish
 	@echo
 
-commit-translation-files: $(POFILES)
-	git add $(POFILES) $(POTFILE) $(ACTIONFILE) ../app/assets/javascripts/katello/locale
+mo-files: $(MOFILES)
+	git add $(POFILES) $(POTFILE) $(JSFILES) ../locale/*/LC_MESSAGES
 	git commit -m "i18n - pulling from tx"
 	@echo
 	@echo Changes commited!
 	@echo
-
-# Workaround when rake task fails (https://github.com/ruby/rake/pull/182)
-extract:
-	rxgettext \
-		--sort-output \
-		--sort-by-msgid \
-		--no-wrap \
-		--no-location \
-		-o ${DOMAIN}.pot \
-		--package-name=${DOMAIN} \
-		--package-version="${VERSION}" \
-		--msgid-bugs-address=foreman-dev@googlegroups.com \
-		--copyright-holder="Foreman developers" \
-		--copyright-year=$(shell date +%Y) \
-		$(shell find ../app -type f -name \*.rb -o -name \*.erb)
diff --git a/locale/action_names.rb b/locale/action_names.rb
deleted file mode 100644
index e0ec9aa6f30..00000000000
--- a/locale/action_names.rb
+++ /dev/null
@@ -1,181 +0,0 @@
-# Autogenerated!
-_("Abstract async task")
-_("Attach subscriptions")
-_("Auto attach subscriptions")
-_("Bulk generate applicability for hosts")
-_("Commit upload")
-_("Copy all units")
-_("Copy content")
-_("Copy version units to library")
-_("Copy version")
-_("Create Alternate Content Source")
-_("Create Container Push Repository Root")
-_("Create Export History")
-_("Create Import History")
-_("Create Syncable Export History")
-_("Create exporter")
-_("Create import")
-_("Create importer")
-_("Create publication")
-_("Create remote")
-_("Create remote")
-_("Create")
-_("Create")
-_("Create")
-_("Create")
-_("Create")
-_("Create")
-_("Create")
-_("Delete Activation Key")
-_("Delete Lifecycle Environment")
-_("Delete Manifest")
-_("Delete Product")
-_("Delete distributions")
-_("Delete orphan alternate content sources")
-_("Delete orphan distributions")
-_("Delete orphan remotes")
-_("Delete orphan repository versions")
-_("Delete orphaned migrated repositories")
-_("Delete remote")
-_("Delete remote")
-_("Delete repository references")
-_("Delete version")
-_("Delete")
-_("Delete")
-_("Delete")
-_("Delete")
-_("Delete")
-_("Delete")
-_("Delete")
-_("Destroy Alternate Content Source")
-_("Destroy Content Host")
-_("Destroy exporter")
-_("Destroy importer")
-_("Destroy")
-_("Disable Simple Content Access")
-_("Disable")
-_("Discover")
-_("Enable Simple Content Access")
-_("Enable")
-_("Environment contents refresh")
-_("Errata mail")
-_("Errata mail")
-_("Export Library")
-_("Export Repository")
-_("Export")
-_("Export")
-_("Export")
-_("Fetch pxe files")
-_("Filtered index content")
-_("Generate host applicability")
-_("Generate metadata")
-_("Generate metadata")
-_("Generate repository applicability")
-_("Hypervisors update")
-_("Hypervisors")
-_("Import Content View Version")
-_("Import Default Content View")
-_("Import Manifest")
-_("Import Repository")
-_("Import migration")
-_("Import repository upload")
-_("Import upload")
-_("Import upload")
-_("Import")
-_("Incremental Update of  Content View Version(s) ")
-_("Incremental Update")
-_("Index content")
-_("Index errata")
-_("Index module streams")
-_("Index package groups")
-_("Initialize")
-_("Instance update")
-_("Metadata generate")
-_("Multi copy all units")
-_("Multi copy content")
-_("Multi copy units")
-_("Product Create")
-_("Promote")
-_("Promotion to Environment")
-_("Publish Lifecycle Environment Container Repositories")
-_("Publish")
-_("Purge completed tasks")
-_("Reclaim space")
-_("Reclaim space")
-_("Refresh Alternate Content Source")
-_("Refresh Manifest")
-_("Refresh all distributions")
-_("Refresh distribution")
-_("Refresh distribution")
-_("Refresh if needed")
-_("Refresh remote")
-_("Refresh remote")
-_("Refresh repos")
-_("Refresh")
-_("Refresh")
-_("Refresh")
-_("Reindex subscriptions")
-_("Remove Content")
-_("Remove Version")
-_("Remove Versions and Associations")
-_("Remove from Environment")
-_("Remove orphans")
-_("Remove orphans")
-_("Remove subscriptions")
-_("Remove units")
-_("Remove units")
-_("Remove unneeded repos")
-_("Repair")
-_("Repositories certs reset")
-_("Repositories gpg reset")
-_("Republish Version Repositories")
-_("Run Sync Plan:")
-_("Save artifact")
-_("Save distribution references")
-_("Save publication")
-_("Save version")
-_("Save versions")
-_("Scan cdn")
-_("Sync capsule")
-_("Sync")
-_("Sync")
-_("Sync")
-_("Syncable export")
-_("Synchronize smart proxy")
-_("Synchronize")
-_("Toggle")
-_("Update Alternate Content Source")
-_("Update CDN Configuration")
-_("Update Content Counts")
-_("Update Content Overrides")
-_("Update content urls")
-_("Update content view environments for host")
-_("Update distributions")
-_("Update http proxy details")
-_("Update http proxy")
-_("Update redhat repository")
-_("Update release version for host")
-_("Update remote")
-_("Update remote")
-_("Update repository")
-_("Update")
-_("Update")
-_("Update")
-_("Update")
-_("Update")
-_("Update")
-_("Update")
-_("Update")
-_("Update")
-_("Updating System Purpose for host")
-_("Updating repository authentication configuration")
-_("Updating repository authentication configuration")
-_("Upload content")
-_("Upload file")
-_("Upload into")
-_("Upload into")
-_("Upload tag")
-_("Verify checksum for content on smart proxy")
-_("Verify checksum of version repositories")
-_("Verify checksum")
-_("Verify checksum")