Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 215965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:31:12+00:00 2026-05-11T18:31:12+00:00

In our JS files we use the following format for Gettext translation: var str1

  • 0

In our JS files we use the following format for Gettext translation:

var str1 = '!t[The text that should be translated]';
var str2 = '!t[Some more text]';

This JS files will be parsed using PHP and the parsed strings get translated via Zend Framework Zend_Translate. The generated JS looks like this:

var str1 = 'The text that should be translated';
var str2 = 'Some more text';

For extracting the strings to be translated and for translating our PHP files we use Poedit, it works very well.
Is there a way to parse the strings to be translated out of '!t[...]' using Poedit?

What would solve the problem is some sort of a Poedit parser that is regex based. Is there any such parser?

As an alternative, we could define a source code parser based on xgettext with the language PHP as parameter(you have to do it because xgettext doesn’t know about .js files and it treats them a C files). Then we use the following format in our JS files:

var str1 = '<?=_t("The text that should be translated")?>';
var str2 = '<?=_t("Some more text")?>';

Needless to say, it’s really uncool to use code that looks like php all over the place just to be able to parse the strings with Poedit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:31:13+00:00Added an answer on May 11, 2026 at 6:31 pm

    A regexp that matches your strings

     $translated = preg_replace('/[\'"]\!t\[(.+)\][\'"]/e', 'translate_function('\\2')', $str);
    

    I don’t know if the \2 should be replaced by \1 or \3, you solution is the “e” modifier provided by the PCRE regex engine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following question. We use log4j in our two projects, that are
We are looking to use GIT to help manage our web files as we
We use .resx files to internationalize our app to several languages. Our automated unit
We use OpenFileDialog across our application to select files. So far, we never used
We have a HSQL .script file in source control. Some of our developers use
We are looking at modifying our build process so that our configuration files are
We use MVC controllers that access System.File.IO in our application and they work fine
I have to use Sync Framework 2.0 in our WPF app that will contain
I have a program that does some networking using Winsock, and one of our
I am trying to backup all the files on our server using some SSH

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.