0

I am new to theme and plugin development and am stuck at the translation part. I read one place that if you are using __(), and e() throughout, you do not need a plugin like WPML. Is it correct? Is generation of the translation files (like .po files) for all the target languages a tough job to do? Will I have to manually copy paste stuff from google translator and paste it in these files? Please excuse my inexperience and thank you or the patience.

6
  • "Will I have to manually copy paste stuff from google translator" - well, WordPress can't actually do the translations for you...
    – vancoder
    Commented Sep 22, 2021 at 16:43
  • @vancoder, thank you for the comment. So I can escape all this by simply using WPML? I mean even without using __(), and e() in development? Commented Sep 22, 2021 at 16:47
  • 1
    Making a theme and plugin ready for translation is one thing, actually translating it another. Have you read the official documentation? developer.wordpress.org/plugins/internationalization and developer.wordpress.org/themes/functionality/…
    – kraftner
    Commented Sep 22, 2021 at 16:48
  • @kraftner I tried, but it is too complex for now at this nascent stage in my career. I just need a simple answer that if I have to use WPML plugin, would I still use __(), and e() in development? Your reply would be greatly appreciated. Commented Sep 22, 2021 at 16:56
  • 1
    @RahilWazir shukriya bhai. ye bichare ek simple si baat ka jawab nahi de rahe kambakht ulte seedhe bas links share kar rahe hain. Commented Sep 22, 2021 at 17:03

1 Answer 1

0

I read one place that if you are using __(), and e() throughout, you do not need a plugin like WPML.

This is not accurate. Those functions and WPML are for two different things.

With a WordPress site you have two kinds of text that might need to be translated:

  1. Content. That is any text entered into WordPress as content that is stored in the database. This includes the body of posts and pages, but also titles, widgets and menus etc.
  2. Template strings. This refers to pieces of text that are coded into templates and functions. For example, your theme might have a "Continue reading" button for each post in a loop. That label is one of these.

The translation functions, __(), _e() etc. are exclusively for dealing with #2, and they are required if you want to allow these strings to be translated. WIthout them these strings will always be the language they were originally written in.

You can either bundle these translations yourself, or just provide a .pot file so that users can create translations themselves. If your theme properly implements localization, and is distributed via the WordPress.org Theme Repository, then users can use https://translate.wordpress.org to create a translation in their language. An overview of localization in WordPress is provided here.

When it comes to #1, content, these functions are not required. Users can set their site to whatever language they like, and enter content in whatever language they like. The only exception is right-to-left languages. To support those a theme needs to provide styles for right-to-left languages. There is a code article on that here.

So what is WPML for? WPML provides tools that allow a site to have content in multiple languages. This is for situations where a site might need to offer content in two or more languages, and allow users to switch between them. WPML is not required to translate template strings, and it's not needed to enter content in any language the author chooses. It's solely for sites that need content in multiple languages.

Some multi-language plugins, like WPML, provide built in tools for translating template strings. These features mean users don't need to depend on the theme author providing a translation, or need to have knowledge of translation tools. However, for these features to work you need to use the translation functions.

To summarise:

  • Proper use of the translation functions allows your theme's hard-coded strings to be translated.
  • You do not need to provide the actual translations yourself. There are other tools users can use to do the translations themselves.
  • Using the translation functions does not give you the features of WPML without a plugin.
  • Users do not need WPML unless they are serving the same content in multiple languages.
  • Always read the documentation. WordPress' documentation on localisation is here.
3
  • This is what I was expecting. Thanks @Jacob :) Commented Sep 25, 2021 at 18:07
  • @RagingVids I see you unaccepted this answer, can you clarify why? What is missing from the answer that prevents it being accepted?
    – Tom J Nowell
    Commented Nov 27, 2021 at 21:50
  • @TomJNowell Im really sorry. I was going through some old questions and must have done this by mistake. Is it fixed now? Commented Nov 29, 2021 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.