How to add a string to a pot file with .php? - localization

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

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.

Related

Torch write text to file

I'm trying to write text to file according to this documentation:
https://github.com/torch/torch7/blob/master/doc/serialization.md
With the following code:
require 'torch'
torch.save('temp.txt','text')
A new file named temp.txt is created but when I open it in text editor I see a few null symbols before the text.
Is there an other way to do it?
torch.save does not write only text to the file, but it serializes the given object, so these bytes are probably type of object and length of the string or similar. This is the intended way.
If you want to write a file with text only, use normal Lua API:
fd = io.open('temp.txt', 'w')
fd:write('text')
fd:close()

How to write CHARACTER variable to file in ESQL?

I'm trying to implement simple message flow, which reads text file (SWIFT message) and replaces one field value, then I need to put it back to file.
Flow reads file as blob, then I cast message as CHARACTER and doing replacement. As result I get a CHARACTER variable, which I want write to file.
Cast the variable back to BLOB, make it the message root, then send it into a FileOutput node with default settings. Assuming that you are doing the character replacement with ESQL in a Compute node (with its Compute Mode set to change Message), then the subsequent ESQL would be:
SET OutputRoot.BLOB.BLOB = CAST(yourCharVar AS BLOB);
To write a simple CHARACTER (for example, a XML tag like '< tag >') to a file in ESQL you just have to create a compute node and add something like:
DECLARE youCharacterToWrite CHARACTER '<a simple string>';
SET OutputRoot.BLOB.BLOB = CAST(youCharacterToWrite AS BLOB CCSID InputRoot.Properties.CodedCharSetId);
And connect your compute node from out terminal to in terminal of your FileOutput to write in the file.
If you debug the variable in IIB, it will show some Base64 representation of your CHARACTER variable, but it will be correctly written to the file.

How to separate the "comma separated values string" whose values in turn contain commas [duplicate]

I have to develop an iOS application that can read the data from a CSV file hosted on a domain. Is there any standard APIs that can help me to do this? I don't need to download but just read the file because the file will be updated for every two mins.
I recommend Dave DeLong's CHCSVParser library for parsing.
You will have to download the file, that is the only way to get it from the remote host to your device. A CSV File is a text file with data separated by a comma(','). Download the file from the the remote host, read the file line by line, split the line string that was read from the file;
For example:
1,2,3,4,1,2,3 ...Line 1
Split using ',' as a delimiter and add the split values into an array, the result will be:
array_line_one = {1,2,3,4,1,2,3};

Extracting files from a zip which is already read as a string in lua

I have a zip file read into a string. I want to reach to its contents using luazip.
According to the manual, filename is given to function zip.open(filename). But I need to use a string of file's content. One way is to write the string to a new zip file and pass its name to the function. But I do not want to create a new file. What is an alternative way of doing this?

Parsing plain text list into multiple text files

I have a collection of daily MP3s that I'm expected to upload to a web server once a month — they're named with a consistent format (ex. 10-17-11 Always Expect the Best # 1.mp3) and for each file, I have to generate an .m3u file with the URL to the web-server link. At the moment, I manually create each .m3u file and save it in relation to the MP3.
There must be a way to generate the .m3u files automatically — they usually are in the format of http://url/audio/2011/10-17-11_.mp3. I've created a plain text list of each filename on a separate line — if possible, I'd like to take that list and parse it into individual .m3u files.
I'm not sure what I should be using to do this — Python, Ruby, maybe just AppleScript?
Any help is greatly appreciated. Thanks!
you probably could do it with any of those, i'll give you a few pointers with python:
with open("my_file","r") as fin: ## open a file for reading
i = 0
for line in fin: ## iterate through all lines
newline = line + line.split(" ")[0] ## create a new line
with open("output"+str(i),"w") as fout: ## open a file for writing
fout.write(newline) ## write...
i+=1
This script reads a file and for each line appends the first word and writes it to its own file.
You can modify the loop code to aggregate several lines each time and write them to a file. And you can extract information from the line you read and use it to construct the new line.

Resources