Internationalizing a ClassicPress plugin: Don’t localize URLs

ClassicPress PluginsThis post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.

When internationalizing a plugin, you should avoid including a URL in the translatable string.

While for ease it may be tempting to do this:

esc_html_e('Please visit <a href="https://development.azurecurve.co.uk/">azurecurve Development</a> for more details.','your-text-domain');

You should instead paramaterize it by doing this:

printf(esc_html__('Please visit %s for more details.', 'your-text-domain'), '<a href="'.esc_url('https://development.azurecurve.co.uk/').'">azurecurve Development</a>');

If you have a URL where you want the anchor text to be translated, you can do this:

printf(esc_html__('Please %sLogin or Register%s to leave a comment.', 'your-text-domain'), '<a href="'.esc_url('https://development.azurecurve.co.uk/login.php').'">', '</a>');

Using a printf or sprintf function will allow you to paramaterize the URL and prevent a translator from substituting your domain for a different one.

Translating a ClassicPress plugin

Internationalizing a ClassicPress plugin
How does internationalization work?
What is a Text Domain and how is it specified?
Localization functions
Which localization functions to use?
Localizing a string
Don't paramaterize your text domain
Localizing a string containing a parameter
Localizing a string including plurals
Localizing a string including notes for the translator
Don't include HTML markup in localization
Don't localize URLs

MDGP “October 2019” Release Feature of the Day: Copy Report Options

Microsoft Dynamics GPThe Inside Microsoft Dynamics GP blog has started a series Feature of the Day posts for Microsoft Dynamics GP “October 2019” Release on which I am following and adding commentary. The index for this series of posts is .

The sixth Feature of the Day is Copy Report Options. This feature allows you use an existing report option with all the report settings and copy it to a new report option for the same report.

When you select the copy action, it will copy all of the settings from the selected report including destination and e-mail options to the new report option being created:

Trial Balance Report Options window showing copy

This is one of the features requested by the community. It will allow you to easily create variations of a report option without needing to do it manually; for myself, this could be quite useful to test changes while dealing with an issue for a client.

Internationalizing a ClassicPress plugin: Don’t include HTML markup in localization

ClassicPress PluginsThis post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.

When internationalizing a plugin, you should, as far as possible, avoid including HTML markup in the localization strings.

Annoyance the First: Thou shalt not put unnecessary HTML markup into the translated string. For example, a heading should not be included in the translatable string like this:

$str = esc_html__('<h3>Section 1</h3>', 'plugin-text-domain');

Instead, it should be included outside the translatable string like this:

$str = '<h3>'.esc_html__('Section 1', 'plugin-text-domain').'</h3>';

This isn’t a rule as such, but more of a guideline. It is sometimes necessary to include HTML markup when emphasis is being added to a specific word where the emphasis in another language may be different. However, bear in mind, that even when the emphasis may be on a single word, you still don’t necessarily need to include it in the translatable string:

$str = sprintf(esc_html__('There are %d lights.', 'plugin-text-domain'), '<em>'.$number.'</em>' );

Another approach to get the same result is to include the markup as the text to replace the placeholders; for example:

$str = sprintf(esc_html__('The cave is %svery%s deep.', 'plugin-text-domain'), '<em>', '</em>' );

Translating a ClassicPress plugin

Internationalizing a ClassicPress plugin
How does internationalization work?
What is a Text Domain and how is it specified?
Localization functions
Which localization functions to use?
Localizing a string
Don't paramaterize your text domain
Localizing a string containing a parameter
Localizing a string including plurals
Localizing a string including notes for the translator
Don't include HTML markup in localization
Don't localize URLs

MDGP “October 2019” Release Feature of the Day: User Access Enhancements

Microsoft Dynamics GPThe Inside Microsoft Dynamics GP blog has started a series Feature of the Day posts for Microsoft Dynamics GP “October 2019” Release on which I am following and adding commentary. The index for this series of posts is .

The fifth Feature of the Day is User Access Enhancements.

There are four enhancements to the User Access window. Firstly, you can choose to filter inactive users from displaying in User Access Setup. This is a per user setting and will be saved the next time you open the window:

User Access Setup

Continue reading “MDGP “October 2019” Release Feature of the Day: User Access Enhancements”

Internationalizing a ClassicPress plugin: Localizing a string including notes for the translator

ClassicPress PluginsThis post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.

The esc_html_x function is very similar to the esc_html__ one, but has the addition of a comment section where context for the translator can be supplied. This is sometimes beneficial to use as the English language has words and phrases which can have different meanings dependent on context.

For example, the word minute:

$str = esc_html_x('Minute', 'measure of time', 'plugin-text-domain');
$str = esc_html_x('Minute', 'extremely small', 'plugin-text-domain');

Translating a ClassicPress plugin

Internationalizing a ClassicPress plugin
How does internationalization work?
What is a Text Domain and how is it specified?
Localization functions
Which localization functions to use?
Localizing a string
Don't paramaterize your text domain
Localizing a string containing a parameter
Localizing a string including plurals
Localizing a string including notes for the translator
Don't include HTML markup in localization
Don't localize URLs

MDGP “October 2019” Release Feature of the Day: Export and Import Workflows

Microsoft Dynamics GPThe Inside Microsoft Dynamics GP blog has started a series Feature of the Day posts for Microsoft Dynamics GP “October 2019” Release on which I am following and adding commentary. The index for this series of posts is .

The fourth Feature of the Day is Export and Import Workflows.

Have you setup a workflow in one company and want to create it in another company? A new workflow feature in Dynamics GP is the ability to Export and Import Workflows. If you export a workflow, a json file will be created with the format of the workflow.:

Workflow Maintenance export of workflow

Continue reading “MDGP “October 2019” Release Feature of the Day: Export and Import Workflows”

Internationalizing a ClassicPress plugin: Localizing a string including plurals

ClassicPress PluginsThis post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.

As well as translating strings, and strings with parameters, you can also translate strings which include plurals. For example, you might have a counts of comments which would vary between 1 comment and 2 comments. This can be handled using the _n function.

There is no equivalent of esc_html__ for the plurals function, so you will need to wrap the _n function call with esc_html__ or esc_html_e:

esc_html_e(sprintf(
    _n(
        '%s comment',
        '%s comments',
        get_comments_number(),
        'plugin-text-domain'
    ),
    number_format_i18n(get_comments_number())
)
);

The _n() function accepts four arguments:

  1. single – the text to be used if the number is singular..
  2. plural – the text to be used if the number is plural.
  3. count – number to compare against to use either the singular or plural form.
  4. text domain – the plugin text domain.

The function returns the correct translated string for the supplied count.

Translating a ClassicPress plugin

Internationalizing a ClassicPress plugin
How does internationalization work?
What is a Text Domain and how is it specified?
Localization functions
Which localization functions to use?
Localizing a string
Don't paramaterize your text domain
Localizing a string containing a parameter
Localizing a string including plurals
Localizing a string including notes for the translator
Don't include HTML markup in localization
Don't localize URLs

Internationalizing a ClassicPress plugin: Localizing a string containing a parameter

ClassicPress PluginsThis post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.

If you have a string containing a parameter, say for example someone making a statement about the number of lights, you can combine your esc_html__ function with sprintf to switch out a placeholder with the number in a variable:

$str = sprintf(esc_html__('There are %d lights.', 'plugin-text-domain'), $number);

The %d will be contained in the string which can be translated; this is necessary as some languages may place the number in a different place of the sentence if it has a different sentence structure.

Translating a ClassicPress plugin

Internationalizing a ClassicPress plugin
How does internationalization work?
What is a Text Domain and how is it specified?
Localization functions
Which localization functions to use?
Localizing a string
Don't paramaterize your text domain
Localizing a string containing a parameter
Localizing a string including plurals
Localizing a string including notes for the translator
Don't include HTML markup in localization
Don't localize URLs

Internationalizing a ClassicPress plugin: Don’t paramaterize your text domain

ClassicPress PluginsThis post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.

A plugin can have a lot of strings to translate; the larger the plugin the more translations there are likely to be. It is quite common for developers to look for ways to reduce typing the same parameter every time through the use of variables or constants, but this must be resisted when it comes to setting the text domain parameter of the localization functions.

The reason for this is that it is not just the PHP of the plugin which needs to parse the translatable strings, but also the gettext libraries which are used to produce the POT templates, used by translators.

gettext is not a PHP parser, so it is unable to read variables or constants; it can only read the strings.

Translating a ClassicPress plugin

Internationalizing a ClassicPress plugin
How does internationalization work?
What is a Text Domain and how is it specified?
Localization functions
Which localization functions to use?
Localizing a string
Don't paramaterize your text domain
Localizing a string containing a parameter
Localizing a string including plurals
Localizing a string including notes for the translator
Don't include HTML markup in localization
Don't localize URLs

MDGP “October 2019” Release Feature of the Day: Security Role and Task Workflows

Microsoft Dynamics GPThe Inside Microsoft Dynamics GP blog has started a series Feature of the Day posts for Microsoft Dynamics GP “October 2019” Release on which I am following and adding commentary. The index for this series of posts is .

The third Feature of the Day is new workflows for Security Role and Task approval.

The last two new workflows are Security Task Approval and Security Roles Approval:

  1. Security Task Approval lets you edit the operations that are assigned to a task or create a new task; and if the workflow is active, the workflow actions will display on Security Task Setup.
  2. Security Roles Approval lets you edit the operations that are assigned to a role or create a new role; and if the workflow is active, the workflow actions will display on Security Role Setup.

With these Security Approval workflows, you can require that any changes made in these windows be submitted for review and approval:

Security Role Setup window

No changes made for Security Tasks or Security Roles will be implemented until the workflow task has been final approved.

I’ve fielded lots of questions over the years from clients asking how they can find out who has changed a role or task. These workflows will allow them to control changes with only a limited number of users able to approve a change and make it live.