Nikerabbit has uploaded a new change for review.
https://gerrit.wikimedia.org/r/65270
Change subject: WIP: Plural support for AndroidFFS
......................................................................
WIP: Plural support for AndroidFFS
Change-Id: Icaf524ddd5605f40c1692857b986a39e9d82fe75
---
M ffs/AndroidXmlFFS.php
1 file changed, 48 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/70/65270/1
diff --git a/ffs/AndroidXmlFFS.php b/ffs/AndroidXmlFFS.php
index 6ce0000..2fcf1bb 100644
--- a/ffs/AndroidXmlFFS.php
+++ b/ffs/AndroidXmlFFS.php
@@ -27,12 +27,17 @@
$messages = array();
$mangler = $this->group->getMangler();
- foreach ( $reader->string as $string ) {
- $key = (string)$string['name'];
- $value = stripcslashes( (string)$string );
+ foreach ( $reader as $element ) {
+ $key = (string)$element['name'];
- if ( isset( $string['fuzzy'] ) &&
(string)$string['fuzzy'] === 'true' ) {
- $value = TRANSLATE_FUZZY . $value;
+ if ( $element->getName() === 'string' ) {
+ $value = stripcslashes( (string)$element );
+ if ( isset( $element['fuzzy'] ) &&
(string)$element['fuzzy'] === 'true' ) {
+ $value = TRANSLATE_FUZZY . $value;
+ }
+ } else {
+ // TODO: process the subelements
+ $value = $this->flattenPlural( array() );
}
$messages[$key] = $value;
@@ -67,13 +72,18 @@
$value = $m->translation();
$value = str_replace( TRANSLATE_FUZZY, '', $value );
- // Kudos to the brilliant person who invented this
braindead file format
- $string = $writer->addChild( 'string', addcslashes(
$value, '"\'' ) );
- $string->addAttribute( 'name', $key );
+ // Handle plurals
+ if ( strpos( $message, '{{PLURAL' ) !== false ) {
+ // TODO Create plurals element with sub elements
+ } else {
+ // Kudos to the brilliant person who invented
this braindead file format
+ $string = $writer->addChild( 'string',
addcslashes( $value, '"\'' ) );
+ $string->addAttribute( 'name', $key );
- // This is non-standard
- if ( $m->hasTag( 'fuzzy' ) ) {
- $string->addAttribute( 'fuzzy', 'true' );
+ // This is non-standard
+ if ( $m->hasTag( 'fuzzy' ) ) {
+ $string->addAttribute( 'fuzzy', 'true'
);
+ }
}
}
@@ -84,4 +94,31 @@
return $dom->saveXML();
}
+
+ /**
+ * Flattens array of plurals into string.
+ *
+ * @param array $forms array
+ * @return string
+ */
+ protected function flattenPlural( array $forms ) {
+ $pls = '{{PLURAL';
+ foreach ( $messages as $key => $value ) {
+ $pls .= "|$key=$value";
+ }
+
+ $pls .= "}}";
+ return $pls;
+ }
+
+ /**
+ * Converts the flattened plural into messages
+ *
+ * @param string $key
+ * @param string $message
+ * @return bool|array
+ */
+ protected function unflattenPlural( $key, $message ) {
+ // See RubyYamlFFS implementation
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/65270
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icaf524ddd5605f40c1692857b986a39e9d82fe75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits