WordPress allows sites, topics, plug-ins, and all content to be translated into all languages. It is part of creating a globally accessible CMS. To translate WordPress sites, developers must write high-quality code to translate topics and plug-ins. Today, we will discuss how to write word press code and translate it through I18N and L10N. Not only that, it can also be translated through wp-pot cli+npm script or gulp. Common structures that can be used to automatically generate pot files are also prepared. But let me talk about translation first. The
WordPress I18N internationalization is the process of writing code ready for translation. There are 18 characters between \
#3 port file generation: the following article explains this. In short, WordPress L10N L10N is similar. There are 10 characters between \
Word press and gettext word press use gettext libraries and tools for I18N. Gettext is an ancient and respected software widely used in the open source world. The following are the methods used in several articles: Developers encapsulate translatable strings in special gettext functions. Special tools will parse source code files and extract translatable strings into pot (portable objects template) files. In the WordPress world, pot files are often provided to translators’ collaboration tool, globpress. The translator translates, and the result is a PO file (a pot file, but it contains a translation). The Po file is compiled as a binary Mo file, allowing faster access to strings at run time. To write I18N code translatable I18N code for WordPress, see this codex page. But let me summarize. The
Text fields must first define a tex domain for a WordPress theme or plug-in, and then in the theme or plug-in header. Yes, made by Carrie DILS – you can also watch word press and international lectures The pot translation file automatically generates topics \/ plug-ins that translators can translate now. Learn how to automatically generate a pot translation file. For easier imitation, we created a common toolkit called wpautopot, which automatically generates pot files through NPM scripts or gulp. Bubble bar. Wpautopot- make sure the settings node is installed. If the node is not ed and installed. Step 1: after installing nodejs and NPM, you can enter the following command to confirm the installation of nodejs and node package manager. If nodejs is not installed, this step only needs to be performed once. No need to repeat. The
Node -v
#V7.10.0
NPM -v
#4.2.02 phase. Package JSON the package in the root folder of the WordPress plug-in or WordPress theme. the JSON file. If you have installed curl, you can execute the following command to it once (make sure that the WordPress plug-in or the root folder of WordPress is opened. Create a theme and the package.json file in it). Male cal-l \
Install WP and pot cli- only run NPM install global WP pot cli terminal. Configure the NPM script -package named pot. After you open the JSON file, you can find it under scripts. Script:{
\
}Changes must be made in the pot script. The
– SRC’**\/* PHP \
language
|└ – wpautopot Pot
≪ – set meal. JSON
♪ gulpfile JS
I see – plug-ins. PHP step 4: now run the NPM script package. Just run the NPM script in the root folder of the WP project where you ed the JSON file. Note: before running, make sure that the language directory exists. Otherwise, running the script will display an error# Compile the pot file.
NPM step 5: use gulp compilation – node dependency to install gulp compilation pot files. Please use the following steps: Otherwise, go to the last step. Currently located in the root folder of the word press plug-in or word press theme. Let’s install node dependencies. Wait for the terminal to run the command and all nodejs dependencies. It only needs to be done once. It may take about 1 minute according to the Internet connection speed# For Mac OS X, run the following command as superuser:
Installing sudo NPM
For Linux, execute the following command:
NPM installation step 6: , configure, and run gulpfile. First, run it in the root folder. the JS file. Volume L \
Ect variables. – \/ \/ \/ – Stop editing project variables. – \/ \/ \/\/-SOP editing project variables. – \/\/\/\/ Stop editing project variables. – \/ \/ (this line) this is a similar project variable introduced in step 3. Now, as long as you run gulp on the command-line terminal, a translated pot file will be generated# Run gulp. Compile the pot file.
Gudong 7 stage: sharing no longer has a stage. Just share it with your friends. Or click to tweet it. Now it’s your turn to automatically generate I18N and L10N pot files. Please tell me what I think about it. If there is a problem, it must be reported to GitHub. The complete request goes far beyond that.