Support » Plugin: Loco Translate » Loco vs filter performance for short strings

  • Resolved menathor

    (@menathor)


    Hi guys!

    Love the plugin. I often use Loco to customise site text. However I only need to replace about 20-30 words for a new project I’m working on so I’m considering using a filter instead:

    add_filter(  'gettext',  'wps_translate_words_array'  );
    function wps_translate_words_array( $translated ) {
    
         $words = array(
                // 'word to translate' = > 'translation'
                'Posts' => 'Article',
                'Post' => 'Articles',
                'Pages' => 'Web pages',
                'Media' => 'Images',
                'Links' => 'Blog Roll',
                );
    
         $translated = str_replace(  array_keys($words),  $words,  $translated );
         return $translated;
    }

    Just wondering if the filter would be any slower or have more of a performance hit than using Loco? And would it be fine replacing a list of 40-50 words this way?

    Thanks- appreciate the advice!

    PS. I’m using opcache and redis

Viewing 1 replies (of 1 total)
  • Plugin Author Tim W

    (@timwhitlock)

    I can’t guess at what a performance comparison would look like.

    What I can say is that parsing MO files is very fast and personally I would not worry about those milliseconds until I had a reason to. I suggest you do some benchmarking and you’ll probably find that MO parsing is a very small part of your overall page render time.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.