• Resolved Trelis

    (@ronantrelis)


    I’m trying to localise my plugin and I have a hyperlink with this format:

    <a href="myurl"> Link Text </a>

    I tried replacing the Link Text as follows:

    <a href="myurl"> __('Link Text','myplugin') </a>

    but this results in an error.

    What is the correct approach to localising the link text? Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @ronantrelis
    To localize the link text in your plugin, you can use WordPress’s __() function. This function retrieves the translation of the string and allows you to specify a text domain for your plugin.

    Here’s an example of how you can use it:

    <a href="myurl"><?php echo esc_html__('Link Text', 'myplugin'); ?></a>

    Use the esc_html__() function to escape the output and prevent security vulnerabilities.

    You will also need to create a translation file for your plugin, which contains the translations of the strings used in your plugin. The translation file should be placed in your plugin’s languages folder and have the following naming convention: {text-domain}-{locale}.mo. For example, the translation file for the myplugin text domain in the English (US) locale would be named myplugin-en_US.mo.

    You can use a plugin like Poedit to create and manage your translation files.

    I hope this helps! Let me know if you have any questions.`

    • This reply was modified 1 year, 11 months ago by Faisal Ahammad. Reason: fixed typo error
    Thread Starter Trelis

    (@ronantrelis)

    Many thanks @faisalahammad , very helpful.

    Here’s what I have now:

    'description' => '<a ><?php echo esc_html__('Learn how to minimise payment processing charges', 'trelis-crypto-payments'); ?></a>',

    and here’s the error I’m getting:

    Parse error: syntax error, unexpected ‘Learn’ (T_STRING), expecting ‘)’ in?/home/customer/www/mysite.com/public_html/wp-content/plugins/Trelis-ethereum-payment-gateway.php_/Trelis-ethereum-payment-gateway.php?on line?190

    Hi @ronantrelis
    It looks like there is an issue with the PHP code in your plugin file. The problem is that you are trying to use PHP tags and functions inside a single-quoted string, which is not allowed.

    To fix the issue, you will need to either use double quotes to define the string or concatenate the string and the PHP code using the . operator:

    Option 1:
    'description' => "<a href='https://docs.trelis.com/features/trelis-prime'>" . esc_html__('Learn how to minimise payment processing charges', 'trelis-crypto-payments') . "</a>",

    Option 2:
    'description' => '<a href="https://docs.trelis.com/features/trelis-prime">' . esc_html__('Learn how to minimise payment processing charges', 'trelis-crypto-payments') . '</a>',

    Either of these options should resolve the parse error you are seeing.

    I hope this helps! Let me know if you have any other questions.

    Thread Starter Trelis

    (@ronantrelis)

    This was incredibly helpful. I appreciate it a lot Faisal, thanks, Ronan

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using gettext for hyperlinks’ is closed to new replies.