All Projects → JDGrimes → wp-l10n-validator

JDGrimes / wp-l10n-validator

Licence: GPL-2.0 License
Gettext localization validator for WordPress

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to wp-l10n-validator

Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+929.41%)
Mutual labels:  i18n, l10n, gettext
Ngettext
A cross-platform .NET implementation of the GNU/Gettext library.
Stars: ✭ 172 (+911.76%)
Mutual labels:  i18n, l10n, gettext
Gotext
Go (Golang) GNU gettext utilities package
Stars: ✭ 292 (+1617.65%)
Mutual labels:  i18n, l10n, gettext
stone.js
gettext-like client-side Javascript Internationalization Library
Stars: ✭ 20 (+17.65%)
Mutual labels:  i18n, l10n, gettext
msgtools
Tools for Developing Diagnostic Messages
Stars: ✭ 18 (+5.88%)
Mutual labels:  i18n, l10n, gettext
Glotpress Wp
🌍 🌎 🌏 GlotPress is a WordPress plugin to let you set up your own collaborative, web-based software translation tool.
Stars: ✭ 205 (+1105.88%)
Mutual labels:  i18n, l10n, gettext
gettext-extractor
A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
Stars: ✭ 82 (+382.35%)
Mutual labels:  i18n, l10n, gettext
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+15894.12%)
Mutual labels:  i18n, l10n, gettext
Kotsu
✨ Clean, opinionated foundation for new projects — to boldly go where no man has gone before
Stars: ✭ 48 (+182.35%)
Mutual labels:  i18n, l10n, gettext
polib
Pure python library to manipulate, create, modify gettext files (pot, po and mo files).
Stars: ✭ 34 (+100%)
Mutual labels:  i18n, l10n, gettext
i18n
Package i18n is for app Internationalization and Localization.
Stars: ✭ 79 (+364.71%)
Mutual labels:  i18n, l10n
python-fluent
Python implementation of Project Fluent
Stars: ✭ 142 (+735.29%)
Mutual labels:  i18n, l10n
arabic-mathjax
Beautiful Arabic Math on all browsers. An extension for MathJax v2.
Stars: ✭ 12 (-29.41%)
Mutual labels:  i18n, l10n
lp-loader
Frictionless language packs for Webpack.
Stars: ✭ 14 (-17.65%)
Mutual labels:  i18n, l10n
oojs-ui
OOUI is a modern JavaScript UI library with strong cross-browser support. It is the standard library for MediaWiki and Wikipedia. This is a mirror from https://gerrit.wikimedia.org. Main website:
Stars: ✭ 45 (+164.71%)
Mutual labels:  i18n, l10n
go-locale
GoLang library used to retrieve the current locale(s) of the operating system.
Stars: ✭ 16 (-5.88%)
Mutual labels:  i18n, l10n
i18n
internationalize projects to Arabic
Stars: ✭ 67 (+294.12%)
Mutual labels:  i18n, l10n
Angular-Gulp-Boilerplate
Clean but full-featured AngularJS boilerplate using Gulp workflow and best practices
Stars: ✭ 30 (+76.47%)
Mutual labels:  i18n, l10n
lisan
🌈i18n, Reimagined! 🚀A blazing fast and super small i18n library for Javascript
Stars: ✭ 85 (+400%)
Mutual labels:  i18n, l10n
inlang
Open Source Localization Solution for Software.
Stars: ✭ 160 (+841.18%)
Mutual labels:  i18n, l10n

WP L10n Validator Build Status

Command-line tool for checking that all strings are properly gettexted for localization in WordPress plugins and themes.

  • Finds any untranslated strings in HTML
  • Finds any untranslated 'encapsed strings' in PHP code
  • Makes sure all gettext function parameters are valid –no variables, function calls, etc., where there should just be an encapsed string– and that all required arguments are present.
  • Makes sure the expected textdomain(s) are always used
  • As a side effect, it also checks that no l10n functions are deprecated.

Installation

Requires: PHP 5.3 or later.

Download a zip, clone the repo, or add to composer dependencies. Add the /bin directory to your $PATH (or use /path/to/wp-l10n-validator/bin/wp-l10n-validator instead of just wp-l10n-validator in your commands.

To see the basic usage and check that everything is working, type the command:

$ wp-l10n-validator

Usage

$ wp-l10n-validator -[1c] TEXTDOMAIN [CONFIG] [-- FILE ...]

This validates all .php files in the current directory for proper gettexting.

Arguments:

  • TEXTDOMAIN - The textdomain used in your project.
  • CONFIG - Configuration to use. Corressponds to one of the directories in /config (wordpress by default).
  • FILE - One or more files to validate. You must pass -- before the list of files, like this: wp-l10n-validator textdomain -- a.php b.php

Flags:

  • 1 - Parse only one file at a time.
  • c - Generate a specific ignores cache. This is a JSON file that contains a list of specific occurrences of strings to ignore. When you have fixed all of the real problems with your project, there may be left many strings that do not need to be gettexted. Running the command with this flag will cache all of those by file name and line number, so that they will be ignored in future. This is especially useful for strings that you want to ignore only in a specific location. If the line number that a string is on changes, but by less than 5 lines, it will continue to be ignored and the line number will be updated in the cache. You can change the number of lines tolerance using the ignores-tolerance configuration option.

The validator will display any errors it finds.

Example validating a plugin:

$ cd /path/to/my-plugin
$ wp-l10n-validator my-plugin

You can also add a wp-l10n-validator.json file in the main directory of your project, which specifies the basic configuration for your project (see below). With this file in place you can run the parser without any arguments.

Configuration

The validator can be configured specifically for your project as needed. Although it can be completely customized, the main reason for additional configuration is to help the parser weed out false positives. The strategy employed for weeding out most false positives is as follows:

  • Ignore non-translatable strings inside calls to certain functions
  • Ignore specific function arguments that don't need to be gettexted
  • Ignore certain HTML attributes' values
  • Ignore specific strings
  • Ignore specific string occurrences

All of these are configurable to match your particular project, though custom configuration is optional. To configure the parser, you can add a JSON file named wp-l10n-validator.json in the root directory of your project (or wherever you wish to run the parser from).

These are the options that you can specify in the the JSON config file:

  • textdomain - Your project's textdomain.
  • basedir - The main directory of your project (if different from the current directory).
  • config - The configuration to use (see CLI arguments above).
  • cache - The file to store the cache in. The default is .wp-l10n-validator-cache.json.
  • ignores-cache - The file to store the specific ignores cache in. The default is .wp-l10n-validator-ignores-cache.json. See the -c flag above for more information.
  • ignores-tolerance - The number of lines of difference to allow for when checking against the ignores cache. The default is 5.
  • ignores-rules - Configure which rules are used to determine if a string should be ignored. It is an associative array with boolean values:
    • all-lowercase — Ignore all strings that contain no uppercase characters. This is a very useful rule to enable if you don't use any translatable strings that are all lowercase. It is disabled by default to avoid false negatives. Add this to your config to enable it:
      	"ignores-rules": {
      		"all-lowercase": true
      	},
  • ignored-functions - An associative array of functions to ignore. The value can be an array of specific arguments to be ignored (by argument number), or simply true. To ignore a class method, add it like this: My_Class::my_method. This will only ignore the method when it is being called statically from outside the class like My_Class::my_method(), or inside the class with self:: or $this->. The parser does not know what class is assigned to a variable, though it does know the variable name. So you can ignore $wpdb->query, (which the parser does ignore by default,) but adding wpdb::query will not match a call to $wpdb->query(). Adding a class constructor (My_Class::__construct) will ignore new My_Class(). Calls within a class to parent::method() will be mapped to the class that is specified in the extends statement. If a method is being ignored in a parent class, it will also be ignored in child classes as well. If a method is being ignored in an interface, all classes that implement that interface will have that method ignored as well (since 0.3.0).
  • ignored-properties - (0.3.0+) An associative array of class properties to ignore. The values are currently just expected to be true. To ignore any strings in the default value for a property, add it like this: My_Class::$my_property. This will only ignore the declared value of the property, it will not ignore assignments (yet). It is possible to ignore the default values for the property in all classes that extend a particular parent class by using the parent class name: Parent_Class::$property.
  • ignored-strings - An array of strings that should always be ignored.
  • ignored-atts - An array of HTML attributes to ignore.
  • ignored-paths - An array of file and folder paths to ignore. (Since 0.2.0)
  • bootstrap - A PHP file providing further, more advanced configuration. You can even write your own child class to extend the validator. This allows you to change the output method by overriding the report_* functions, for example. Just assign and instance of your class to the $parser variable: $parser = new My_L10n_Validator.

See example-config.json for an example.

Notes

  • Though written primarily as a CLI app, it may also be used directly from within another script to validate a single file or a directory. Only the later option is available from the default CLI usage.
  • Don't let the WP fool you. Though written primarily for WordPress, it can easily be configured for other frameworks that use similar gettexting methods.

Credits

License

Dual licensed under GPLv2 and MIT licenses.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].