It seems that your text is the same way to use gettext:
  & Lt ;? Php echo _ ("my text"); ? & Gt;   Of course, you can not add quotation marks only when you are using variables, since then the variable name will be output in a literal form, such as:
 < Code> & lt ;? Php echo _ ("$ myText") ;? & Gt;   does not work.
In a related post, the answer indicates that you can not use the string variable, and you will need the code in the variable name, $ myText, in the poedit file itself. Of course, this is not optimal, but it can work.
Can not work, however, when you have a project loop that spreads a php variable which can be defined hundreds of times if you have:
  & lt ;? Php foreach ($ variable as $ variable) {echo $ variable; }? & Gt;   and calculation ($ variable)> 100, or even 10, this solution will be prohibitive. Is there a better way ??
  xzetext  (or  poedit ) Is a "static analyzer", which means that it does not run your code, it only finds all the  _ ()  functions, and assumes that there is nothing in it to translate String for 
 So, if you do:  _ ('hello, world')  
 then string  hello, world  
The code will expire in your .po file.
 This is often a good thing, because it allows us to remove some redundancy in your translation files. If we have 3 planets, then we need four translation strings; For a  hello, $ planet, , and one for every planet 
 If we want to add  bye, $ planets , then we need to add only an additional translation string, and not 3. 
Just to make sure that you understand that :-) Now, more specificity on the subject of your question:
You will need a hardcode variable name, $ MyText, only in poedit file Of course, this is not optimal, but it can work.
 This will not work because all  $ myText  variables will solve the same translation string. I doubt this is what you want? 
 Where is your variable coming from? If they are from a database or third-party API, then you can see some different solutions, such as scanning your database for translation strings, or getting all the strings from the third-party API. 
 If you insert them, the string in the  .po  file will work fine by using  _ ($ var) , because lookup is done automatically on runtime. 
 Another possible solution is to create your own function, let's call it the  v_ ()  (variable for v). At runtime, this function reads the content of a  .po  file (or possibly a database, which is later converted to a  .po  file), and if String '
  function v _ ($ str) {global $ translation_mode;   If ($ translate_mode &! String_in_po_file ($ str)) insert_string_in_po_file ($ str); Return _ ($ str); }    Because it is executed on  run-time , we know the content of the string. In this example we use a  $ translate_mode  variable so this code has only the minimum overhead on the production machines. 
Comments
Post a Comment