diff --git a/templates/locale.gen.j2 b/templates/locale.gen.j2
index 149dfda3584c302a27db2d860c640cda729e40f1..cde41b4012601d12541c6974efaf08e5c9319ec5 100644
--- a/templates/locale.gen.j2
+++ b/templates/locale.gen.j2
@@ -1 +1,3 @@
-{{ locale | regex_replace('^([a-z]{2,3}(_[A-Z]{2})?(@[^.]*)?)(\..*)?$', '\\1') }} {{ (locale | regex_replace('^([a-z]{2,3}(_[A-Z]{2})?(@[^.]*)?)(\.(.*))?$', '\\5')).upper() | default('UTF-8',true) }}
+{% for locale_item in locale -%}
+{{ locale_item | regex_replace('^([^\.]+)(\..*)?$', '\\1') }} {{ (locale_item | regex_replace('^[^\.]*(\.(.*))?$', '\\2')).upper() | default('UTF-8',true) }}
+{% endfor %}