Please, do not use "cg" to mean "category group **translation**": it kinda confused me.

If in the unlikely case where all translations are missing from a category group, this task will not generate anything.
I would have iterated on the groups, then the locales and initialized "name" either with the first available translation for that same group or its tag if not found.
And if you want to save some queries, you can cache found translations **inside** each category group loop.