Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit 80471ba

Browse files
author
Shawn Hooper
committed
implement editor for matching strings
1 parent 20ed66f commit 80471ba

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

classes/ReactIntlEditor/ReactIntlEditor.php

+31
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ public function getMissingStringCount($locale) {
192192
return $i;
193193
}
194194

195+
/***
196+
* @param $locale
197+
*
198+
* @return int
199+
*/
200+
public function getMatchingStrings() {
201+
202+
if ($this->locale === null) {
203+
throw new Exception('ReactIntlEditor was not instansiated with a locale');
204+
}
205+
206+
$matches = [];
207+
208+
foreach ($this->sourceStrings as $sourceString) {
209+
foreach ($this->localeStrings[$this->locale] as $localeString) {
210+
if ($localeString[0] == $sourceString->id) {
211+
$combinedString = array(
212+
'id' => $sourceString->id,
213+
'defaultMessage'=> $sourceString->defaultMessage,
214+
'description' => $sourceString->description,
215+
'message' => $localeString[1]
216+
);
217+
array_push( $matches, $combinedString );
218+
continue;
219+
}
220+
}
221+
}
222+
223+
return $matches;
224+
}
225+
195226
/***
196227
* @param $locale
197228
*

editor.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
$reactIntlEditor = new \ReactIntlEditor\ReactIntlEditor($locale);
1515

1616
switch ($type) {
17+
case 'matching':
18+
$stringsArray = $reactIntlEditor->getMatchingStrings();
19+
break;
1720
case 'missing':
18-
$missing = $reactIntlEditor->getMissingStrings();
21+
$stringsArray = $reactIntlEditor->getMissingStrings();
1922
break;
2023
default:
2124
throw new \ReactIntlEditor\Exception('Unknown String Type Specified in Querystring');
@@ -51,34 +54,34 @@
5154
<button class="submitbutton">Save Changes</button>
5255
</div>
5356

54-
<?php $i=0; foreach ($missing as $string) { ?>
57+
<?php $i=0; foreach ($stringsArray as $string) { ?>
5558

5659
<table class="translate_item" id="translate-table-<?php echo $i; ?>">
5760
<thead>
5861
<tr>
59-
<td><span class="key"></strong><?php echo $string->id; ?></span></td>
62+
<td><span class="key"></strong><?php echo ($type == 'missing') ? $string->id : $string['id']; ?></span></td>
6063
<td></td>
6164
<td>Translated Text for <?php echo $locale; ?> locale</td>
6265
</tr>
6366
</thead>
6467
<tbody>
6568
<tr>
6669
<td class="original">
67-
<p><span id="original-<?php echo $i;?>"><?php echo $string->defaultMessage; ?></span></p>
70+
<p><span id="original-<?php echo $i;?>"><?php echo ($type == 'missing') ? $string->defaultMessage : $string['defaultMessage']; ?></span></p>
6871
</td>
6972
<td>
7073
<button class="copybutton" data-id="<?php echo $i; ?>">Copy &gt;</button>
7174
</td>
7275
<td>
73-
<textarea class="translation" name="<?php echo $string->id; ?>" id="translation-<?php echo $i; ?>"></textarea>
76+
<textarea class="translation" name="<?php echo ($type == 'missing') ? $string->id : $string['id']; ?>" id="translation-<?php echo $i; ?>"><?php if ($type == 'matching') { echo ($type == 'matching') ? $string['message'] : ''; } ?></textarea>
7477
</td>
7578
</tr>
7679
</tbody>
77-
<?php if ($string->description !== null && $string->description !== $string->defaultMessage) { ?>
80+
<?php if ( ($type == 'matching' && $string['description'] !== null && $string['description'] !== $string['defaultMessage']) || ($type == 'missing' && $string->description !== null && $string->description !== $string->defaultMessage) ) { ?>
7881
<tfoot>
7982
<tr>
8083
<td colspan="3">
81-
<strong>Context:</strong><br /><?php echo $string->description; ?>
84+
<strong>Context:</strong><br /><?php echo ($type == 'missing') ? $string->description : $string['description'] ?>
8285
</td>
8386
</tr>
8487
</tfoot>

0 commit comments

Comments
 (0)