Adds function to use variables with i18n Ref. #208. Adjusts cropping ratio for collection.

This commit is contained in:
Mateus Machado Luna 2019-03-15 12:47:47 -03:00
parent 706b89353d
commit eb56d6e301
5 changed files with 31 additions and 6 deletions

View File

@ -61,12 +61,12 @@
<p
v-if="uploadedItems.length > 0 && (uploadedItems.length - amountFinished) > 1"
class="has-text-gray">
{{ (uploadedItems.length - amountFinished) + " " + $i18n.get('label_files_remaining') }}
{{ $i18n.getWithVariables('label_%s_files_remaining', [(uploadedItems.length - amountFinished)]) }}
</p>
<p
v-if="uploadedItems.length > 0 && (uploadedItems.length - amountFinished) == 1"
class="has-text-gray">
{{ "1 " + $i18n.get('label_file_remaining') }}
{{ $i18n.get('label_one_file_remaining') }}
</p>
</div>

View File

@ -20,7 +20,7 @@
<b-checkbox
@click.native.prevent="selectAllItems()"
v-model="isAllItemsSelected">
{{ `${$i18n.get('label_select_all')} ${totalItems} ${$i18n.get('items').toLowerCase()}` }}
{{ `${$i18n.getWithVariables('label_select_all_%s_items', [totalItems])}` }}
</b-checkbox>
</span>
</div>

View File

@ -91,6 +91,30 @@ I18NPlugin.install = function (Vue, options = {}) {
let string = tainacan_plugin.i18n['helpers_label'][entity][key].description;
return (string != undefined && string != null && string != '' ) ? string : "Invalid i18n helper object. ";
},
/**
* Parsed strings created with variables according to WordPress Logic.
* Check https://developer.wordpress.org/themes/functionality/internationalization/#variables
* An example: ('This sentence has %s letters', [nLetters])
* or ('This one has %1$s letters and %2$s words', [nLetters, nWords]).
*/
getWithVariables(key, variables) { // TRY WITH regex: \%((\d)\$)*s
let rawString = tainacan_plugin.i18n[key];
if (rawString != undefined && rawString != null && rawString != '' ) {
console.log(rawString)
let splits = rawString.match(/\%((\d)\$)*s/gm); // An array with all the %s, %1$s, %2$s, etc
let parsedString = '';
for (let i = 0; i < splits.length; i++) {
parsedString += rawString.split(splits[i]).join(variables[i]);
}
console.log(parsedString)
return parsedString;
} else {
"Invalid i18n key: " + tainacan_plugin.i18n[key];
}
}
}
};

View File

@ -137,7 +137,7 @@ export default {
this.params.flex_width = true;
this.params.flex_height = true;
this.params.width = 2000;
this.params.height = 280;
this.params.height = 625;
}
this.frame = wp.media({

View File

@ -337,8 +337,8 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_selected_terms' => __( 'Selected terms', 'tainacan' ),
'label_editing_item_number' => __( 'Editing item n.', 'tainacan' ),
'label_sequence_editing_item' => __( 'Sequence editing: Item', 'tainacan' ),
'label_files_remaining' => __( 'files remaining.', 'tainacan' ),
'label_file_remaining' => __( 'file remaining.', 'tainacan' ),
'label_%s_files_remaining' => __( '%s files remaining.', 'tainacan' ),
'label_one_file_remaining' => __( 'One file remaining.', 'tainacan' ),
'label_upload_file_prepare_items' => __( 'Uploading files and preparing items', 'tainacan' ),
'label_bulk_edit_items' => __( 'Bulk edit items', 'tainacan' ),
'label_sequence_edit_items' => __( 'Sequence edit items', 'tainacan' ),
@ -377,6 +377,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_delete_item' => __( 'Delete item', 'tainacan' ),
'label_no_collections_using_taxonomy' => __( 'There is no collection using this taxonomy', 'tainacan' ),
'label_collections_using' => __( 'Collections using', 'tainacan' ),
'label_select_all_%s_items' => __( 'Select all %s items', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),