Submit
Path:
~
/
home
/
bfxleof
/
www
/
wp-content
/
plugins
/
loco-translate
/
src
/
gettext
/
File Content:
WordCount.php
<?php /** * Experimental PO/POT file word counter. * Word counts are approximate, including numbers and sprintf tokens. * Currently only used for source words in latin script, presumed to be in English. */ class Loco_gettext_WordCount implements Countable { /** * @var LocoPoIterator */ private $po; /** * Source Words: Cached count of "msgid" fields, presumed en_US * @var int */ private $sw; /** * Create counter for a pre-parsed PO/POT file. * @param Loco_gettext_Data */ public function __construct( Loco_gettext_Data $po ){ $this->po = $po; } /** * @internal */ private function countField( $f ){ $n = 0; foreach( $this->po as $r ){ $n += self::simpleCount( $r[$f] ); } return $n; } /** * Default count function returns source words (msgid) in current file. * @return int */ public function count(){ $n = $this->sw; if( is_null($n) ){ $n = $this->countField('source'); $this->sw = $n; } return $n; } /** * Very simple word count, only suitable for latin characters, and biased toward English. * @param string * @return int */ public static function simpleCount( $str ){ $n = 0; if( is_string($str) && '' !== $str ){ // TODO should we strip PHP string formatting? // e.g. "Hello %s" currently counts as 2 words. // $str = preg_replace('/%(?:\\d+\\$)?(?:\'.|[-+0 ])*\\d*(?:\\.\\d+)?[suxXbcdeEfFgGo%]/', '', $str ); // Strip HTML (but only if open and close tags detected, else "< foo" would be stripped to nothing if( false !== strpos($str,'<') && false !== strpos($str,'>') ){ $str = strip_tags($str); } // always html-decode, else escaped punctuation will be counted as words $str = html_entity_decode( $str, ENT_QUOTES, 'UTF-8'); // Collapsing apostrophe'd words into single units: // Simplest way to handle ambiguity of "It's Tim's" (technically three words in English) $str = preg_replace('/(\\w+)\'(\\w)(\\W|$)/u', '\\1\\2\\3', $str ); // Combining floating numbers into single units // e.g. "£1.50" and "€1,50" should be one word each $str = preg_replace('/\\d[\\d,\\.]+/', '0', $str ); // count words by standard Unicode word boundaries $words = preg_split( '/\\W+/u', $str, -1, PREG_SPLIT_NO_EMPTY ); $n += count($words); /*/ TODO should we exclude some words (like numbers)? foreach( $words as $word ){ if( ! ctype_digit($word) ){ $n++; } }*/ } return $n; } }
Submit
FILE
FOLDER
Name
Size
Permission
Action
AjaxRouter.php
6839 bytes
0644
Data.php
13150 bytes
0644
DownloadConfController.php
945 bytes
0644
Extraction-20260622064208.php
6492 bytes
0644
JsonSerializable.php
577 bytes
0644
LimitStream.php
4209 bytes
0644
Matcher.php
9218 bytes
0644
SearchPaths-20260622063747.php
3016 bytes
0644
SyncOptions-20260622141726.php
2310 bytes
0644
SyncOptions.php
2310 bytes
0644
WordCount.php
2907 bytes
0644
class-sitemaps-admin-20260705091211.php
3665 bytes
0644
class-sitemaps-admin.php
3665 bytes
0644
class-tracking-server-data.php
1989 bytes
0644
class-wpseo-statistics.php
1443 bytes
0644
ctrl.package.php
17073 bytes
0644
deactivation-20260705060759.php
21118 bytes
0644
deactivation.php
21118 bytes
0644
duplicator-20260704004435.php
1781 bytes
0644
duplicator.php
1781 bytes
0644
elFinderVolumeLocalFileSystem.class-20260623050500.php
48544 bytes
0644
elFinderVolumeLocalFileSystem.class-20260624192801.php
48544 bytes
0644
elFinderVolumeLocalFileSystem.class.php
48544 bytes
0644
exceptions.php
708 bytes
0644
flexible-widget.php
11167 bytes
0644
inc.validator.php
5401 bytes
0644
loco.php
5626 bytes
0644
manager.php
14659 bytes
0644
module.php
1297 bytes
0644
quick-edit-handler-1650.js
1848 bytes
0644
request-methods-header.php
1127 bytes
0644
setup.php
2699 bytes
0644
uninstall.php
4401 bytes
0644
N4ST4R_ID | Naxtarrr