WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using localization in iframes (3 posts)

  1. SpiritOfTheWinds
    Member
    Posted 1 year ago #

    Hi,

    I've got a problems while trying to use gettext inside iframes. I'm linking to PHP pages (which has included the WordPress header) and using the gettext function to get those pages to translate. Unfortunately, it keeps using the default language even if I specify the locale.

    I'd like any help which could help me fix the localization of those pages. I want to use the same .MO/.PO that my theme use.

    So, I have my language files as theme_name\en_US.po and my iframe files in theme_name\forms\form_name.php.

    Those forms have <?php include("../../../../wp-blog-header.php"); ?> and $locale = ($_GET['lang'] == 'fr') ? 'fr_CA' : 'en_US'; define('WPLANG', $locale); setlocale(LC_ALL, $locale);. I tried forcing the locale however the setlocale and define does nothing and it keeps showing me the default language text. I know it's loading cause the text is not the same, even in the default language. I just can't seem to figure out how to force a language in a file outside the WordPress theme files.

    Bit more code:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <?php include("../../../../wp-blog-header.php"); ?>
    <?php $locale = ($_GET['lang'] == 'fr') ? 'fr_CA' : 'en_US';
    load_theme_textdomain('theme', get_template_directory());
    define('WPLANG', $locale);
    setlocale(LC_ALL, $locale); ?>
    <title><?php bloginfo('name'); ?> - <?php _e('theme', 'Test Form') ?></title>
    [...]

    The default language is fr_CA. Any help on this issue would be greatly appreciated!

    Thanks!

    P.S. Couldn't post to the WP-Advanced forum so I posted here instead.

  2. SpiritOfTheWinds
    Member
    Posted 1 year ago #

    Well, a colleague got an idea that worked. I created a new page that used a new template (which contained the form) and linked it in my iframe. It is working fine though I would have preferred if it wasn't listed in the Pages list. But it works and it's the important.

  3. SpiritOfTheWinds
    Member
    Posted 1 year ago #

    Sorry, forgot to mark as resolved! Now done.

Topic Closed

This topic has been closed to new replies.

About this Topic