Fix broken HTML

Fix broken HTML

If the HTML from the theme or other plugins is not very well formatted, it can sometimes cause issues when using TranslatePress.
For example, using duplicated attributes in a tag can cause missing attributes, which in turn can lead to unexpected behavior of the website when browsing a translated page.
We have solutions that attempt fixing broken HTML. Go to Settings -> TranslatePress -> Advanced tab.

Activate option Fix spaces between HTML attributes first (attributes without spaces between them are not valid HTML)
If the first fix doesn』t work, try activating option Fix broken HTML. Only try this if you still have problems after using the first solution

If your issue is still not solved, look for bad formatting in the missing HTML and correct it in the plugins/theme.
Common bad formatting includes duplicate attribute on same tag, like the class attribute in the following example:

The correct version would be:

Exclude a certain text or element from being translated

Exclude a certain text or element from being translated

There are situations when you might want to exclude a certain HTML element from being translated by TranslatePress.
How to exclude text or an element from being translated
You can easily achieve this by using the following attribute: data-no-translation.

Attributes provide additional information about HTML elements.

Let』s say we want to exclude a certain paragraph of text from being translated.

This is a paragraph of text that will be excluded from translations.

This can be easily done for any HTML element (list, form, div, etc.) to exclude it from being translated.

You can achieve the same thing programmatically in PHP by using the filter trp_no_translate_selectors.

add_filter( 'trp_no_translate_selectors', 'trpc_no_stranslate_selectors', 10, 2);
function trpc_no_stranslate_selectors($selectors_array, $language){
$selectors_array[] = '.do_not_translate_css_class';
$selectors_array[] = '#do_not_translate_css_id';
return $selectors_array;
}

Note: This will exclude from being translated all the element』s child elements.

To exclude a certain element from being translated in the front-end use the attribute data-no-dynamic-translation. This differs from the data-no-translation attribute because it still allows the translation of the element in the server side. It will only stop being detected in the client side using JS. 

In other words, dynamic changes over this element will be ignored.

This is a paragraph of text that will be translated only on the server side. Dynamic changes to this element using JS will not be detected.

There is also a filter where you can programmatically add other selectors to be excluded from dynamic translation:  trp_skip_selectors_from_dynamic_translation

/**
*
* Skip dynamic detection of strings.
*
*/
add_filter( 'trp_skip_selectors_from_dynamic_translation', 'trpc_skip_dynamic_translation' );
function trpc_skip_dynamic_translation( $skip_selectors ){
$add_skip_selectors = array( '.section', '.other-section' ); // replace with a list of selectors
return array_merge( $skip_selectors, $add_skip_selectors );
}

You might also want to check out the Advanced Settings tab in TranslatePress which lets you:

Exclude selectors from translation
Exclude Gettext strings
Exclude from dynamic translation

Disable translation of Gettext strings

Disable translation of Gettext strings

Strings outputted by WordPress themes or plugins are called Gettext strings. Translating these types of strings through TranslatePress can be unnecessary if they are already translated or you plan to translate them using the .po/.mo translation file system.

Disabling this feature of TranslatePress can improve the page load perfomance of you site in certain cases.

Download and activate the following plugin to disable translation of Gettext strings. No other setting is necessary.

Download Disable Gettext Strings Translation Add-on

Disable SQL errors notices

Disable SQL errors notices

TranslatePress has a system that tracks SQL errors and helps you display them.
This system can be disabled in some cases, for example:

false positives
errors that announce various problems, these being false.

With the help of this code, TranslatePress no longer:

records SQL errors
prevents admin notices from appearing
and disables automatic translation

If you want to insert this custom code, follow these steps:
1. Create an empty plugin like this:
https://gist.github.com/sareiodata/76f701e01db6685829db
2. Add the following code to the end of it:
add_filter('trp_disable_error_manager','__return_true');
 
3. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality.

Delete all translations and plugin data

Delete all translations and plugin data

How to delete all translations and plugin data
TranslatePress saves your translations into the database – however, deleting the plugin won』t erase them (in order not to accidentally lose all your work).
If you』re looking to remove all the translations and plugin data, you will have to access your database using a management tool like phpMyAdmin and manually delete the created tables, options and meta keys.
Below are the exact steps you need to take to remove all plugin data (translations included) from your database:
1. Deleting the tables
Here is a list of all the tables which are created by TranslatePress:

wp_trp_dictionary* – the dictionary tables contain manually or automatically translated strings
wp_trp_gettext* – the gettext tables contain theme/plugin strings which already have a translation
wp_trp_original_strings – the original strings table contains strings in the default language, without any translation
wp_trp_original_meta – the original meta table contains meta information which refers to the post parent』s id

2. Deleting the options and meta keys
You can achieve this manually or by using the SQL queries mentioned below.
Here is a list of all the options and meta keys created by TranslatePress, along with the tables in which they are inserted:

_postmeta table – meta keys inserted into the _postmeta table have the _trp_ prefix
_termmeta table – meta keys inserted into the _termmeta table have the _trp_ prefix
_options table – options inserted into the _options table have the trp_ prefix
_usermeta table – meta keys inserted into the _usermeta table have the _trp_ prefix

In order to automatically delete all the data mentioned above, the following queries can be used:

delete from wp_options where option_name like 'trp_%';
delete from wp_termmeta where meta_key like '_trp_%';
delete from wp_postmeta where meta_key like '_trp_%';
delete from wp_usermeta where meta_key like '_trp_%';

Note: The default WordPress database prefix is wp_ , replace it with your own database prefix.
By following the 2 steps above you』ll remove all existing translations and plugin data added by TranslatePress to your database.

Clickable Language Switcher

Clickable Language Switcher

By default the language switcher dropdown will open once you hover over it.
If you』re looking to make the dropdown language menu of the language switcher be displayed only when you click on it, you can use the following plugin:

Clickable Language Switcher (2877 downloads)

Change language name

Change language name

Looking to change the language name displayed in the language switcher?
If you』re using the Full Language Name option for your language switcher it is possible to change the language name that will be displayed to your users using the option of adding a new custom language, by following the steps below:
1. Add a new custom language with the language code of the language you wish to change the name of from TranslatePress -> Advanced -> Custom Language.You can read more about Custom Languages here.
2. You can find the correct language code by adding the language you wish to change the name of in General settings and copying the code. You can skip this step if you have already installed the language you want to change.

3. Change the language name to the desired name:

4. Modify the name by editing the language code and the language name. The rest of the languages will not change.
5. Do not forget to click the Add button and to save the changes.
Now you can select the language with the desired name from the language menu in General Setting.

Change hreflang localization

Change hreflang localization

TranslatePress sets meta tags inside the html page to help Google and other indexing engines understand the languages and locations that a specific page is available in.

The hreflang attribute is a part of this meta tag where the language and location are specified.

You can change it using a bit of coding:

1. Create an empty plugin like this:https://gist.github.com/sareiodata/76f701e01db6685829db

2. Add the following code to the end of it:

add_filter('trp_hreflang', 'trpc_change_hreflang', 10, 2 ); function trpc_change_hreflang( $hreflang, $language ){ if ($language == 'fr_FR'){ // language code that you want to alter // the modified hreflang code you want to display in the page $hreflang = 'fr-CH'; } return $hreflang; }

3. Modify the code by editing the language code and the hreflang code. The rest of the hreflang codes will not change.

4. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality

Add a custom language

Add a custom language

If you need to translate your WordPress site in a language that is not found in the All Languages drop-down you can easily add a custom language.
This feature lets you add one or more custom languages directly from TranslatePress Advanced Settings. Once the language(s) is added it will appear and can be selected from the languages list.
Steps to Add a Custom Language to your Multilingual WordPress Site
To add a custom language, navigate to TranslatePress -> Settings and select the Advanced tab. Then click the 「Custom language」 section.

Here you』ll be asked to input the following custom language details:

Language Code: the language code of the language, which will be used in the url
Language name: the name of the language, as it will appear in the languages list.
Native name: the native language name, which will be used only if you select the option to display languages in their native names
Automatic translation code: the code used by Google Translate or DeepL to do the automatic translations
Flag URL: in order to add a flag to your language, simply upload a PNG file into the WordPress media library and then copy its URL here (TranslatePress will take care of the resizing)
Text RTL: check only if the custom language is written in right to left format

Once you』ve added all the custom language details don』t forget to click the Add button and then Save Changes. Your custom language will now appear in the language list and you can select it.

After this, your custom language will appear in the front-end translation interface.

It will also be listed in the language switcher:

The premium version of TranslatePress has no limitation on the number of custom languages that you can add. In the free version the number of translation languages is limited to two.
Following these steps you can start translating your site in any language you want. Even Klingon!

 
Editing an existing language
If you wish to edit the name or the flag of an existing language you can achieve this by going to TranslatePress -> Advanced Tad -> Custom Languages.
You can add the Language Code of the language you wish to edit. The language code can be found in General Settings under Code.

Fill in the Language Code and the changes you want to make. The Language Code field is required but apart from that any field left unfilled will be automatically completed with the rest of the information.

By doing this you can edit the name or the flag of an existing language. After clicking Add and saving the changes, the language will appear in General settings under Custom Languages.