Question

A lot of my website content is stored in a database for this reason I created a script that goes through the content stored in the database and extracts strings that must be added to my .pot file. (which already contains other strings).

I created a function called "add_string($s)" that should add one string to the .pot file but I'm not sure how to do it.

function add_string($s)
{
// Add string to .pot file?
}

How can this be done?

Thanks

Was it helpful?

Solution

A pot file is just a text file in certain format.

You can use file_put_contents with the FILE_APPEND flag to add text to a file.

With regards to the format of the data argument of the file_put_contents call, you will have lines referencing files starting with #:, lines referencing instructions to translators starting with #. and then lines starting with msgid with the message id and msgstr the message value. You will want to include the newline \n after each line.

See here for an example of the pot file format.

You will probably want to keep track of your strings in PHP data structure as you write them to file or before you write them to file, to avoid duplicating message values in the template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top