+
+ /**
+ * Get the grammar transformations data for the language.
+ * Used like grammar forms, with {{GRAMMAR}} and cases,
+ * but uses pairs of regexes and replacements instead of code.
+ *
+ * @return array[] Array of grammar transformations.
+ * @since 1.28
+ */
+ public function getGrammarTransformations() {
+ $languageCode = $this->getCode();
+
+ if ( self::$grammarTransformations === null ) {
+ self::$grammarTransformations = new MapCacheLRU( 10 );
+ }
+
+ if ( self::$grammarTransformations->has( $languageCode ) ) {
+ return self::$grammarTransformations->get( $languageCode );
+ }
+
+ $data = [];
+
+ $grammarDataFile = __DIR__ . "/data/grammarTransformations/$languageCode.json";
+ if ( is_readable( $grammarDataFile ) ) {
+ $data = FormatJson::decode(
+ file_get_contents( $grammarDataFile ),
+ true
+ );
+ if ( $data === null ) {
+ throw new MWException( "Invalid grammar data for \"$languageCode\"." );
+ $data = [];
+ }
+
+ self::$grammarTransformations->set( $languageCode, $data );
+ }
+
+ return $data;
+ }
+