Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've created a PHP script that takes a correctly formatted Localizable.strings file as input and produced a Localizable.h file as output containing appropriate #define-commands for each String-Key. You can modify it as you see fit.</p> <p>The script expects all string keys to be formatted with sub-words split by uppercase letters, so a line should look like this in your Localizable.strings file:</p> <pre><code>"SectionSomeString" = "This is my string."; </code></pre> <p>which would then be converted to</p> <pre><code>#define SECTION_SOME_STRING NSLocalizedString(@"SectionSomeString", nil) </code></pre> <p>The PHP script looks as follows:</p> <pre><code>&lt;?php /** Script for generating constants out of Localizable.strings files Author: Gihad Chbib */ define("INPUT_FILE", "Localizable.strings"); define("OUTPUT_FILE", "Localizable.h"); define("HEADER_COMMENT", "// Auto-generated constants file - don't change manually!"); if (file_exists(INPUT_FILE)) { $file = fopen(INPUT_FILE, "r"); $defineconstant = str_replace(".", "_", OUTPUT_FILE); $output = HEADER_COMMENT."\n\n"; $output .= "#ifndef _".$defineconstant."\n"; $output .= "#define _".$defineconstant."\n"; while (!feof($file)) { $lineOfText = fgets($file); if ((strstr($lineOfText, "=") !== FALSE) &amp;&amp; (substr($lineOfText, -2) === ";\n")) { $arr = explode("=", $lineOfText); $defineKey = str_replace("\"", "", $arr[0]); $constructedKey = ""; for ($i=0; $i&lt;strlen($defineKey); $i++) { $letter = $defineKey[$i]; if (preg_match('/[a-z|A-Z]$/',$letter)==true) { $ucletter = strtoupper($letter); if (($ucletter === $letter) &amp;&amp; ($i !== 0)) { $constructedKey .= "_".$ucletter; } else { $constructedKey .= $ucletter; } } else { $constructedKey .= $letter; } } $defineKey = trim($defineKey); $constructedKey = trim($constructedKey); $output .= "#define $constructedKey NSLocalizedString(@\"$defineKey\", nil);\n"; } else if (substr($lineOfText, 0, 2) == "//") { $output .= "\n$lineOfText\n"; } } $output .= "\n#endif\n"; echo nl2br($output); fclose($file); // Save file file_put_contents(OUTPUT_FILE, $output, LOCK_EX); } else { echo "Input file ".INPUT_FILE." not found"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload