Create more than you consume

I’m now writing over at my brand new site. Check it out and follow along.

Mass Create All Translation Sets with GlotPress

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

https://glotpress.blog/2010/04/09/mass-create-translation-sets/

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 ) {
                continue;
            }
        }
    }

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 🙂 


Comments

Leave a Reply

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