summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/insertables/MediaWikiInsertablesSuggester.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Translate/insertables/MediaWikiInsertablesSuggester.php')
-rw-r--r--www/wiki/extensions/Translate/insertables/MediaWikiInsertablesSuggester.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/www/wiki/extensions/Translate/insertables/MediaWikiInsertablesSuggester.php b/www/wiki/extensions/Translate/insertables/MediaWikiInsertablesSuggester.php
new file mode 100644
index 00000000..11aea35b
--- /dev/null
+++ b/www/wiki/extensions/Translate/insertables/MediaWikiInsertablesSuggester.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * @file
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ */
+
+/**
+ * Insertable is a string that usually does not need translation and is
+ * difficult to type manually.
+ * @since 2013.09
+ */
+class MediaWikiInsertablesSuggester {
+ public function getInsertables( $text ) {
+ $insertables = [];
+
+ $matches = [];
+ preg_match_all( '/\$(1[a-z]+|[0-9]+)/', $text, $matches, PREG_SET_ORDER );
+ $new = array_map( function ( $match ) {
+ return new Insertable( $match[0], $match[0] );
+ }, $matches );
+ $insertables = array_merge( $insertables, $new );
+
+ $matches = [];
+ preg_match_all(
+ '/({{((?:PLURAL|GENDER|GRAMMAR):[^|]*)\|).*?(}})/i',
+ $text,
+ $matches,
+ PREG_SET_ORDER
+ );
+ $new = array_map( function ( $match ) {
+ return new Insertable( $match[2], $match[1], $match[3] );
+ }, $matches );
+ $insertables = array_merge( $insertables, $new );
+
+ $matches = [];
+ preg_match_all( '/<\/?[a-z]+>/', $text, $matches, PREG_SET_ORDER );
+ $new = array_map( function ( $match ) {
+ return new Insertable( $match[0], $match[0] );
+ }, $matches );
+ $insertables = array_merge( $insertables, $new );
+
+ return $insertables;
+ }
+}