• Resolved olligranlund

    (@olligranlund)


    Hey

    I’ve been using gettext variables in my plugins but for some reason they are not visible in Loco Translates string gettext scan. I also created a dummy plugin to test this out and the result was that gettext variables inside a class wouldn’t be visible, and gettext variables in functions, would work every now and then.

    I can see the issue with these strings:
    <?php _e( 'First Name', 'somesite_registration' ) ?>
    __( '<strong>ERROR</strong>: You must include your phone number.', 'somesite_registration' )

    These are not the only strings having this issue. I’ve been reading on the WordPress I18n and used their functions, but I’m still stuck with the issue.

    One of my plugins I translated fully manually and imported that data to Loco Translate. Pressing “Sync” would then remove all the strings except for the ones in plugin description, author etc.

    WP_Debug is on, and not giving me any errors. Any ideas what could be causing this issue?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Tim W

    (@timwhitlock)

    The string extractor is not aware of whether strings are inside functions or classes, as it is not a syntactical parser. My guess is that whatever is wrong, this factor is not the distinction.

    If you have problems extracting from strings from specific code, please post the code in full. (Your example above is not valid PHP, because your second call to __ is outside the escape tags).

    Also, have take a look at the Help for authors page in the manual.

    Thread Starter olligranlund

    (@olligranlund)

    Thanks for the quick reply, really appreciated.

    About the second call, it’s from another part of my script and inside PHP-tags ??

    I just noticed that if I have the translation done separately, it still wont be translated to default language. I guess this means your plugin is working fine and the issue is somewhere else in my code.

    Here is anyways one example of my code:
    `<p>
    <label for=”phone”><?php _e( ‘Phone’, ‘somesite_registration’ ) ?><br />
    <input type=”tel” name=”phone” id=”phone” class=”input” value=”<?php echo esc_attr( wp_unslash( $phone ) ); ?>” size=”25″ /></label>
    </p>`

    ******And here is my translation for it in a .po file for Finnish*******

    ...
    #: somesite_scripts.php:116
    msgid "Phone"
    msgstr "Puhelin"
    ...
    • This reply was modified 7 years, 11 months ago by olligranlund. Reason: Wrong formatting
    • This reply was modified 7 years, 11 months ago by olligranlund.
    • This reply was modified 7 years, 11 months ago by olligranlund.
    • This reply was modified 7 years, 11 months ago by olligranlund.
    Plugin Author Tim W

    (@timwhitlock)

    I guess this means your plugin is working fine and the issue is somewhere else in my code

    I don’t see a problem here either. If your plugin declares superopisto_registration as its text domain, then the extractor should work. (See the Help for Authors page for how to declare your text domain)

    The only other thing to check is whether the PHP file is being skipped. Check it has one of the supported .php file extensions and is under the maximum file size limit. https://localise.biz/wordpress/plugin/manual/settings#xgettext

    If you can’t pin the problem on Loco Translate, please mark this issue as resolved. Thanks.

    Thread Starter olligranlund

    (@olligranlund)

    You are so right. I guess I need to dig deeper~ Anyways I want to say thank you for these quick replies ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Loco Translate can’t find strings in functions or classes’ is closed to new replies.