Getitng a Twig Lang value dynamically - dynamic

I have a question about how I can pull a deep nested translation value from Twig dynamically.
Here is the setup:
I have my translations files in yml format (en.yml), here is an example:
parent:
child:
something: here is some test
another: more text here
I then have an array passed to Twig:
array(2) {
[0]=>
array(2) {
["name"]=>
string(2) "GS"
["folders"]=>
array(1) {
[0]=>
array(1) {
["name"]=>
string(3) "something"
}
}
[1]=>
array(2) {
["name"]=>
string(1) "I"
["folders"]=>
array(2) {
[0]=>
array(3) {
["name"]=>
string(2) "another"
}
}
In twig, I want to print the folder names to screen, e.g.
here is some test
It would be easy if the lang file had everything in its root, I could use:
{{ array.folders.name|trans }}
However as this is a nested value in the lang file I somehow need to say:
{{'parent.child'.array.folders.name|trans }}
Any help would be very much appricated.

Simply first concatenate the string, then pass the value to the translator filter as follow:
{{ ('parent.child.' ~ array.folders.name)|trans }}
Hope this help

Related

Convert properties from properties file into json in Dataweave 2.0

How to convert properties from a properties file
creditmaster.metadata.AverageFicoScore=700
creditmaster.a.b.c=xyz
into this json format in a generic way
{
creditmasterMetaData: [
{
attributeKey: "AverageFicoScore",
attributeValue: 700
}
]
}
This script is generic in that it doesn't matter what are the parts of the key, it only groups by the first element (before of the first dot) and the key name after the last dot, it ignores everything in the middle:
%dw 2.3
output application/java
import * from dw::core::Strings
fun mapProperties(props) =
entriesOf(props) // since Mule 4.3 / DW 2.3
filter (substringAfter($.key, ".") startsWith "metadata.") // to filter keys with .metadata.
groupBy ((item, index) -> substringBefore(item.key, "."))
mapObject ((value, key, index) ->
(key): value map {
attributeKey: substringAfterLast($.key, "."),
attributeValue: if (isInteger($.value)) $.value as Number else $.value
}
)
---
mapProperties(payload)
Input file:
creditmaster.metadata.AverageFicoScore= 700
other.a.b= 123
creditmaster.a.b.c=xyz
something.metadata.another.maximum=456
creditmaster.metadata.different.minimum=500
Output (in JSON for clarity):
{
"something": [
{
"attributeKey": "maximum",
"attributeValue": "456"
}
],
"creditmaster": [
{
"attributeKey": "minimum",
"attributeValue": "500"
},
{
"attributeKey": "AverageFicoScore",
"attributeValue": "700"
}
]
}
One alternative is using the pluck function. It lets you iterate over an object receiving the entries.
If you have this input
{
"creditmaster": {
"metadata": {
"AverageFicoScore": "700",
"OtherData": "Some value"
}
}
}
with this transformation
{
creditmasterMetaData:
payload.creditmaster.metadata pluck ((value, key, index) ->
{
attributeKey: key,
attributeValue: value
}
)
}
you get this output
{
"creditmasterMetaData": [
{
"attributeKey": "AverageFicoScore",
"attributeValue": "700"
},
{
"attributeKey": "OtherData",
"attributeValue": "Some value"
}
]
}

Multiple Patterns for Regex Expression MongoDB Atlas

I'm trying to get a MongoDB aggregate pipeline working. I need to match name to "John" and regex their "hometown" field to regex matching "CAPETOWN" or "FLORIDA" without case sensitivity. Basically if either of those patterns exist in the "hometown" field of the document. This is what I have so far.
const news = await cachedDb.collection(COLLECTION).aggregate([
{ $match: { "name": "John", "hometown": { $regex: /CAPETOWN/, $options: 'i' } } }
]).toArray();
I can only get CAPETOWN included, I want an OR. Such as "hometown" contains CAPETOWN OR FLORIDA with option (i). How do I go about doing that?
You have to set OR directly in the regex string.
db.collection.aggregate([
{
$match: {
"hometown": {
$regex: "CAPETOWN|FLORIDA",
$options: "i"
}
}
}
])
You can test it here

Mule dataweave issue with when condition

Need help with a when condition in Dataweave transformation. My data weave transformer is populating email address in an output java object. The input email address comes from flow variable. I want to hydrate the output object only if email is stored in flow variable.
Below is the code I have and if I try to add a when condition, it throws an error. Can anyone please help with this conditional logic?
maintainContactInformationData: {
effectiveDate: flowVars.currentDate,
workerContactInformationData: {
emailAddressData: [{
emailAddress: flowVars.email ,
usageData: [{
typeData: [{
primary: true,
typeReference: {
ID: [{
type: "Communication_Usage_Type_ID",
value: "WORK"
} as :object {
class : "com.workday.hr.CommunicationUsageTypeObjectIDType"
}]
} as :object {
class : "com.workday.hr.CommunicationUsageTypeObjectType"
}
} as :object {
class : "com.workday.hr.CommunicationUsageTypeDataType"
}]
} as :object {
class : "com.workday.hr.CommunicationMethodUsageInformationDataType"
}]
} as :object {
class : "com.workday.hr.EmailAddressInformationDataType"
}] when flowVars.email != null,
If you want emailAddressData to be added to output only when email variable is set the. You should include it in parenthesis ...
(emailAddressData: logic to get) when flowVars.email? And flowVars.email != ""

How does one deal with a group of login fields in Yodlee?

For normal username/password fields, it's pretty straight forward with a single key value pair, but I recently encountered a complicated Content Service, which has a group of fields (birth date), do we resubmit in plural form or as if they were separate fields?
Example:
Normal Form:
["componentList"]=>
array(4) {
[0]=>
object(stdClass)#3 (13) {
["valueIdentifier"]=>
string(5) "LOGIN"
["valueMask"]=>
string(11) "LOGIN_FIELD"
["fieldType"]=>
object(stdClass)#6 (1) {
["typeName"]=>
string(4) "TEXT"
}
["size"]=>
int(20)
["maxlength"]=>
int(15)
["name"]=>
string(5) "LOGIN"
["displayName"]=>
string(7) "User ID"
["isEditable"]=>
bool(true)
["isOptional"]=>
bool(false)
["isEscaped"]=>
bool(false)
["helpText"]=>
string(5) "85046"
["isOptionalMFA"]=>
bool(false)
["isMFA"]=>
bool(false)
}
Weird plural form:
[3]=>
object(stdClass)#11 (19) {
["defaultValues"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["values"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["validValues"]=>
array(3) {
[0]=>
array(12) {
[0]=>
string(2) "01"
[1]=>
string(2) "02"
[2]=>
string(2) "03"
[3]=>
string(2) "04"
}
[1]=>
array(31) {
[0]=>
string(2) "01"
[1]=>
string(2) "02"
[2]=>
string(2) "03"
[3]=>
string(2) "04"
}
[2]=>
NULL
}
["valueIdentifiers"]=>
array(3) {
[0]=>
string(8) "OPTIONS1"
[1]=>
string(7) "OPTIONS"
[2]=>
string(6) "LOGIN1"
}
["valueMasks"]=>
array(3) {
[0]=>
string(12) "/LOGIN_FIELD"
[1]=>
string(11) "LOGIN_FIELD"
[2]=>
string(12) "/LOGIN_FIELD"
}
["fieldTypes"]=>
array(3) {
[0]=>
object(stdClass)#9 (1) {
["typeName"]=>
string(7) "OPTIONS"
}
[1]=>
object(stdClass)#8 (1) {
["typeName"]=>
string(7) "OPTIONS"
}
[2]=>
object(stdClass)#14 (1) {
["typeName"]=>
string(4) "TEXT"
}
}
["validationRules"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["sizes"]=>
array(3) {
[0]=>
int(20)
[1]=>
int(20)
[2]=>
int(20)
}
["maxlengths"]=>
array(3) {
[0]=>
int(40)
[1]=>
int(40)
[2]=>
int(4)
}
["userProfileMappingExpressions"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["name"]=>
string(26) "Date of Birth (MM/DD/YYYY)"
["displayName"]=>
string(26) "Date of Birth (MM/DD/YYYY)"
["isEditable"]=>
bool(true)
["isOptional"]=>
bool(false)
["isEscaped"]=>
bool(false)
["helpText"]=>
string(5) "85043"
["isOptionalMFA"]=>
bool(false)
["isMFA"]=>
bool(false)
}
When sending this grouping back to the API, I currently flattened it so it's like:
credentialFields[3]
credentialFields[4]
credentialFields[5]
With each containing the relevant data for the date, month and year. However, perhaps we are supposed to roll it up as plurals in the same way it comes down? Is there an example of one of these multi-value forms for the REST API?
You are correct certain financial institutions do have multiple fields in groups, DOB is one of them. I have done successful implementation for the same. Since I did the same in purely SOAP, however I do not have any sample for REST implementation so what all I can tell you that is you do not need to flatten the list simply fill in the required answers in the original list and send back the form with your request.

how to display product image in order history in prestashop

I need to display product image in order details page when user click order details link.
I have edited below code in order-detail.tpl but it not shows product image it shows only some dummy image
<td>
<a href="{$link->getProductLink($product.product_id, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">
<img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'small_default')}" alt="{$product.name|escape:'htmlall':'UTF-8'}" {if isset($smallSize)}width="{$smallSize.width}" height="{$smallSize.height}" {/if} /></a>
</td>
I want to do this in PS 1.3 version, and I have problem too :/ When I display {$product.image|var_dump} variable I get NULL
Function getImageLink($product.link_rewrite, $product.id_image, 'small_default') working good, but the problem is to get values from variables $product.link_rewrite and $product.id_image but I unfortunately don't know how to.
Now they are empty and so on links to image is incorrect
If that page you can view the variable what comes with $product. Like this.
{$product|var_dump}
and you will notice that $product have a array value image which is a object
so now go with this.
{$product.image|var_dump}
and you will view all this value.
object(Image)#490 (26) {
["id"]=>
int(1)
["id_image"]=>
string(1) "1"
["id_product"]=>
string(1) "3"
["position"]=>
string(1) "1"
["cover"]=>
string(1) "1"
["image_format"]=>
string(3) "jpg"
["source_index"]=>
string(52) "/Applications/MAMP/htdocs/prestashop/img/p/index.php"
["folder":protected]=>
NULL
["existing_path":protected]=>
NULL
["id_lang":protected]=>
NULL
["id_shop":protected]=>
int(1)
["id_shop_list"]=>
NULL
["get_shop_from_context":protected]=>
bool(true)
["table":protected]=>
string(5) "image"
["identifier":protected]=>
string(8) "id_image"
["fieldsRequired":protected]=>
array(1) {
[0]=>
string(10) "id_product"
}
["fieldsSize":protected]=>
array(0) {
}
["fieldsValidate":protected]=>
array(3) {
["id_product"]=>
string(12) "isUnsignedId"
["position"]=>
string(13) "isUnsignedInt"
["cover"]=>
string(6) "isBool"
}
["fieldsRequiredLang":protected]=>
array(0) {
}
["fieldsSizeLang":protected]=>
array(0) {
}
["fieldsValidateLang":protected]=>
array(0) {
}
["tables":protected]=>
array(0) {
}
["webserviceParameters":protected]=>
array(0) {
}
["image_dir":protected]=>
string(43) "/Applications/MAMP/htdocs/prestashop/img/p/"
["def":protected]=>
array(6) {
["table"]=>
string(5) "image"
["primary"]=>
string(8) "id_image"
["multilang"]=>
bool(true)
["fields"]=>
array(3) {
["id_product"]=>
array(3) {
["type"]=>
int(1)
["validate"]=>
string(12) "isUnsignedId"
["required"]=>
bool(true)
}
["position"]=>
array(2) {
["type"]=>
int(1)
["validate"]=>
string(13) "isUnsignedInt"
}
["cover"]=>
array(3) {
["type"]=>
int(2)
["validate"]=>
string(6) "isBool"
["shop"]=>
bool(true)
}
}
["classname"]=>
string(5) "Image"
["associations"]=>
array(1) {
["l"]=>
array(3) {
["type"]=>
int(2)
["field"]=>
string(8) "id_image"
["foreign_field"]=>
string(8) "id_image"
}
}
}
["update_fields":protected]=>
NULL
}
You will notice that there is not value of link_rewrite. So you need to pass that from the controller.