<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: cigati.ir</title>
    <description>The latest articles on DEV Community by cigati.ir (@playus_ir_878d8a2eb38f5da).</description>
    <link>https://dev.to/playus_ir_878d8a2eb38f5da</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4265054%2Fac16425b-04f0-4686-994b-9758ddb0e4eb.png</url>
      <title>DEV Community: cigati.ir</title>
      <link>https://dev.to/playus_ir_878d8a2eb38f5da</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/playus_ir_878d8a2eb38f5da"/>
    <language>en</language>
    <item>
      <title>How I Built a Zero-Backend Binary .MO Compiler &amp; WordPress POT Translator in the Browser</title>
      <dc:creator>cigati.ir</dc:creator>
      <pubDate>Wed, 25 Nov 2026 15:27:36 +0000</pubDate>
      <link>https://dev.to/playus_ir_878d8a2eb38f5da/how-i-built-a-zero-backend-binary-mo-compiler-wordpress-pot-translator-in-the-browser-26n7</link>
      <guid>https://dev.to/playus_ir_878d8a2eb38f5da/how-i-built-a-zero-backend-binary-mo-compiler-wordpress-pot-translator-in-the-browser-26n7</guid>
      <description>&lt;p&gt;If you have ever localized a WordPress theme or WooCommerce plugin, you probably ran into the same two annoying options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pay &lt;strong&gt;$39.99/year&lt;/strong&gt; for desktop software like Poedit Pro just to scan PHP source code and auto-translate strings.&lt;/li&gt;
&lt;li&gt;Install an in-dashboard plugin like Loco Translate that runs directly inside your live WordPress site, eating PHP memory and cluttering your admin panel.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I wanted something faster, free, and 100% client-side—so I built &lt;a href="https://www.cigati.ir/" rel="noopener noreferrer"&gt;POT Translator AI&lt;/a&gt;, a browser-based localization suite for WordPress developers. Here is a quick technical look at how the core pieces work under the hood.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Compiling Binary &lt;code&gt;.mo&lt;/code&gt; Files in 1ms with &lt;code&gt;ArrayBuffer&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Many developers don't realize that WordPress &lt;strong&gt;never reads &lt;code&gt;.po&lt;/code&gt; text files at runtime&lt;/strong&gt;. PHP strictly requires compiled binary &lt;code&gt;.mo&lt;/code&gt; (Machine Object) files.&lt;/p&gt;

&lt;p&gt;Instead of spinning up a Linux backend running &lt;code&gt;msgfmt&lt;/code&gt;, you can compile GNU Gettext &lt;code&gt;.mo&lt;/code&gt; binaries directly in JavaScript using &lt;code&gt;TextEncoder&lt;/code&gt;, &lt;code&gt;ArrayBuffer&lt;/code&gt;, and &lt;code&gt;DataView&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Header (28 bytes):&lt;/strong&gt; Little-endian magic number (&lt;code&gt;0x950412de&lt;/code&gt;), format revision (&lt;code&gt;0&lt;/code&gt;), number of strings (&lt;code&gt;N&lt;/code&gt;), byte offset of the original strings table (&lt;code&gt;O&lt;/code&gt;), byte offset of the translated strings table (&lt;code&gt;T&lt;/code&gt;), and hashing table size/offset (&lt;code&gt;0&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorting Requirement:&lt;/strong&gt; Gettext requires original (&lt;code&gt;msgid&lt;/code&gt;) entries to be sorted lexicographically by their UTF-8 byte representation so PHP's binary search can resolve strings in &lt;code&gt;O(log n)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;String Tables:&lt;/strong&gt; Each entry stores &lt;code&gt;(length, offset)&lt;/code&gt; as two 32-bit unsigned integers, followed by null-terminated UTF-8 payloads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result? Compiling a 3,000-string WooCommerce catalog into a valid &lt;code&gt;.mo&lt;/code&gt; binary takes &lt;strong&gt;~1 millisecond&lt;/strong&gt; in the browser with zero server uploads. You can test the standalone &lt;a href="https://www.cigati.ir/po-to-mo-converter" rel="noopener noreferrer"&gt;PO to MO online converter&lt;/a&gt; directly without uploading anything to a server.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Protecting &lt;code&gt;%s&lt;/code&gt; and HTML Placeholders During AI Translation
&lt;/h2&gt;

&lt;p&gt;One of the easiest ways to crash a WordPress site (White Screen of Death) is letting an LLM translate or drop a PHP &lt;code&gt;printf&lt;/code&gt; placeholder like &lt;code&gt;%s&lt;/code&gt;, &lt;code&gt;%d&lt;/code&gt;, or &lt;code&gt;%1$s&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Before sending batches to an AI model (or a user's own BYOK endpoint like OpenAI, Claude, DeepSeek, or local Ollama), our tokenizer isolates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;printf&lt;/code&gt; specifiers (&lt;code&gt;%s&lt;/code&gt;, &lt;code&gt;%d&lt;/code&gt;, &lt;code&gt;%1$s&lt;/code&gt;, &lt;code&gt;%%&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;HTML tags (&lt;code&gt;&amp;lt;a href="..."&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Shortcodes and curly-brace variables (&lt;code&gt;{order_number}&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After translation, a client-side QA validator compares every &lt;code&gt;msgid&lt;/code&gt; against its &lt;code&gt;msgstr&lt;/code&gt; and flags any missing or mismatched tokens before you export.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Client-Side ZIP Unpacking &amp;amp; PHP/JS Source Scanning
&lt;/h2&gt;

&lt;p&gt;What if a theme author forgot to include a &lt;code&gt;.pot&lt;/code&gt; template? Using &lt;code&gt;JSZip&lt;/code&gt; in the browser, we unpack the uploaded &lt;code&gt;.zip&lt;/code&gt;, scan &lt;code&gt;.php&lt;/code&gt; and &lt;code&gt;.js&lt;/code&gt; files for WordPress Gettext calls (&lt;code&gt;__()&lt;/code&gt;, &lt;code&gt;_e()&lt;/code&gt;, &lt;code&gt;_x()&lt;/code&gt;, &lt;code&gt;esc_html__()&lt;/code&gt;, &lt;code&gt;esc_attr__()&lt;/code&gt;), and generate a clean &lt;code&gt;.pot&lt;/code&gt; template on the fly—making it a &lt;a href="https://www.cigati.ir/poedit-alternative" rel="noopener noreferrer"&gt;free online Poedit alternative&lt;/a&gt; with zero installation.&lt;/p&gt;

&lt;p&gt;We also built a dual-pane &lt;a href="https://www.cigati.ir/online-po-editor" rel="noopener noreferrer"&gt;online PO editor&lt;/a&gt; with keyboard shortcuts, Find &amp;amp; Replace, and persistent client-side Translation Memory (&lt;code&gt;IndexedDB&lt;/code&gt;) so common strings like &lt;code&gt;"Add to cart"&lt;/code&gt; or &lt;code&gt;"Save Changes"&lt;/code&gt; are auto-filled at zero token cost across projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  Safe Deployment Tip for WordPress Developers
&lt;/h2&gt;

&lt;p&gt;Never place your compiled &lt;code&gt;.mo&lt;/code&gt; files inside &lt;code&gt;wp-content/plugins/your-plugin/languages/&lt;/code&gt;—WordPress wipes that folder on every plugin update. Always deploy to the global update-proof directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wp-content/languages/plugins/{textdomain}-{locale}.mo
wp-content/languages/themes/{textdomain}-{locale}.mo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want the full breakdown of safe paths, text domains, and Gutenberg Jed 1.x JSON script translations, check out our &lt;a href="https://www.cigati.ir/how-to-translate-wordpress-plugins" rel="noopener noreferrer"&gt;WordPress plugin translation guide&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;I'd love to hear how other WordPress devs handle i18n in 2026—are you still using Poedit, WP-CLI, or something custom? Drop a comment below!&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
