Mass Create All Translation Sets with GlotPress

November 28, 2018| Mike Stott

We’ve been setting up translation support for extensions using GlotPress. If you’re using this too you may have hit the problem of having to add each set one by one, from GlotPress.

When you create a new project, it doesn’t have any translations and all translation sets have to be created one by one

This was super time consuming with over 200+ translation sets to add. Sure, you could just add the main ones, but why not do it properly and add them all?

The solution? Some code 🙂

I wrote a small snippet of code to do this for me, which I hacked in to fire on the first translation set create. This then loops through and adds them all for me. It uses the English name for the name of the set and the default option for the slug. 

Be sure to change your project ID (if it isn’t your first project in your GlotPress install)

    public function make_all_sets(){
        $locales = GP_Locales::locales();
        foreach($locales as $k => $v){      
            $the_set = array(
                'locale' => $k,
                'name' => $v->english_name,
                'slug'  => 'default',
                'project_id' => 1 //update as your own ID
            $created_set = GP::$translation_set->create_and_select( $the_set );
            if ( !$created_set ) {

That’s all there is to it, the above will loop through all the sets and create them for you.

If this has helped you in any way, please like, share and comment on this post 🙂 

Categories: Coding

Leave a Reply

Your email address will not be published. Required fields are marked *