react-intl composite message - intl

I'm struggling to work out the best way to structure messages whereby one of the dynamic values also needs a translation.
For example if I have the message 'Type in Spanish...' I would like to use this message in every different combination for all the languages my app supports.
Assuming only en/es are supported then I would required a function that could output the following combinations:
Type in Spanish...
Type in English...
Escribir en español...
Escribir en ingles...
With 3 supported languages there would be 9 possible combinations etc...
The only way I can think to do it is by composing messages as follows:
const messages = defineMessages({
language: {
id: 'language',
description: 'The name of the language',
defaultMessage: 'English'
},
typeInLanguage: {
id: 'typeInLanguage',
description: 'instructs the user to type their message in a specific language',
defaultMessage: 'Type in { language }'
}
})
FormattedMessage
{...messages.typeInLanguage}
values={{
language: <FormattedMessage {...messages.language} />
}} />
I've got a feeling that this is not the optimal way. Perhaps there are some languages where the the standalone form of the word 'English' is not the same when used in the context of the phrase 'Type in English...'
I guess that's a hypothetical concern and I don't know enough about languages to know if that is a problem or not.
Is the above approach of composing messages a valid one?

Related

In a Quiz, how can i instead of "Say A, B or C" let the user use one of the three response words?

VIA Actions Console, not Dialogflow!
After several days I finally finished to create a Quiz that works like this.
Google Mini says: "What is the capital of France? A) Rome, B) Berlin or C) Paris ?"
In my scene i have two conditions.
scene.slots.status == "FINAL" && intent.params.choosenABC.original == session.params.antwort
AND
!(scene.slots.status == "FINAL" && intent.params.choosenABC.original == session.params.antwort)
So here, these conditions check whether the user says the correct letter coming from the session parameter "antwort".
Everything works smooth as long as the user says "A", "B" or "C".
But how can i compare a condition to what the user says?
In the above example i want the user to be able to say "Rome" or "Berlin" or "Paris" and the condition to check these entries.
Thanks in advance!
You have a number of questions packed in there, so let's look at each.
Does input.params.original exist?
In short, yes. You can see the documentation of the request Intent object and you'll see that there is intent.params.*name*.original. Your question seems to suggest this would work as well.
There is also intent.params.*name*.resolved which contains the value after you take type aliases into account.
I found some variables on a Dialogflow forum...
Those only work if you're using Dialogflow and don't make any sense when you're looking at Action Builder.
How to match
You don't show the possible value of session.params.antwort or how you're setting antwort. But it sounds like it makes sense that you're setting this in a handler. So one thing you could do is to set antwort to the city name (or whatever the full word answer is) and set letter to the letter with the valid reply. Then test both against original to see if there is a match.
But, to be honest, that starts getting somewhat messy.
You also don't indicate how the Intent is setup, or if you're using an Entity Type to capture the answer. One great way to handle this, however, is to create a Type that can represent the answers, and use a runtime type override to set what the possible values and aliases for that value are. Then, you can control exactly what the valid value you will use to compare with will be.
For example, if you create a type named "Answer", then in your fulfillment when you ask the question you can set the possible values for this with something like
conv.session.typeOverrides = [{
name: 'Answer',
mode: 'TYPE_REPLACE',
synonym: {
entries: [
{
name: 'A',
synonyms: ['A', 'Rome']
},
{
name: 'B',
synonyms: ['B', 'Berlin']
},
{
name: 'C',
synonyms: ['C', 'Paris']
}
]
}
}];
If you then have an Intent with a parameter of type Answer with the name answer, then you can test if intent.parameter.answer.resolved contains the expected letter.
Adding a visual interface
Using runtime type overrides are particularly useful if you also decide to add support for a visual selection response such as a list. The visual response builds on the runtime type override to add visual aliases that users can select on appropriate devices. When you get the reply, however, it is treated as if they said the entry name.

Conditional text replacement

I'm pre-processing some ecommerce product titles, such as:
Input:
1. Jersey Shore: Family Vac Season 2
2. Robotic Vac Cleaner with Max Power Suction
Notice that booth titles have a Vac word. I would like to correct the 2nd one, replacing it to Vaccum.
Desired output:
1. Jersey Shore: Family Vac Season 2
2. Robotic Vaccum Cleaner with Max Power Suction
I could write a algorithm (for instance checking if the string contains "clean" or "suction"), but first I would like to know if there are any frameworks, libraries, etc that already does this kind of task. Seems to be a commom problem... It could be any language (java, python, c, etc).
I could think that you are getting those tittles from an API or are them hardcoded in the site?
If you have it in a JSON format or even in something more simple as an array of strings:
var products = [{
'title': "Jersey Shore: Family Vac Season 2",
}, {
'title': 'Robotic Vac Cleaner with Max Power Suction',
}]
There is a very useful Javascript tool ->
https://fusejs.io/
With it you can search and even specify nice parameters like:
threshold -> if you want a perfect match or similar words, etc.
Visit the site the documentation is great.
After that you can use Javascript (String.prototype.replace) replace with the word that you want, in this case: Vaccum
https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/String/replace
And get your final object or array to be placed on your ecommerce site

Algolia transliteration Cyrillic strings

Does anyone have experience with Algolia & transliteration? For example indexes contain Cyrillic text but user is typing in latin letters.
Unfortunately, most search engines don't support transliteration natively; same for Algolia.
The best way to handle such a use-case is to enrich your objects with the transliterated attributes before sending them to the search engine.
Maybe you can try gausby/translitit-cyrillic-russian-to-latin?
Just to add one little clarification. Let's say we have one field like name and many name translations
you can form object like
{
name: 'whatever',
translations: {
ru: 'без разницы',
he: 'οτιδήποτε',
de: 'was auch immer'
}
}
Then you put in your searchable attributes name, translations.ru, translations.he, translations.de so search will return 'whatever' when user type in 'без ра' for example.

Can I use rowmode: 'array' in combination with named parameters?

Is it possible to have rowMode: 'array' and named parameters at the same time? Right now, with the code below, I'm getting syntax error at or near "$"
db.query({
text: `
select task_nr, commitment
from surveys
where email = $<email> and id = $<id>
order by task_nr
`,
values: {email: email, id: id},
rowMode: 'array',
})
No, it is not possible, because rowMode is strictly part of the Parameterized Query, which by definition forwards query formatting to the driver->server where such thing as Named Parameters does not exist.
Unfortunately, if you really need to use rowMode, you can only use the basic $1, $2... variable formatting as supported by the server.
Strictly speaking, rowMode is not that valuable, it is fairly easy to reformat the data, and then just use pg-promise default formatting with all its nice formatting features.

JQuery UI Autocomplete returning all values

I have the following code:
$("#auto").autocomplete({
source: "js/search.php",
minLength: "3" });
This code is assign to an input text box where i type a name and after 3 letters it should return the ones that have similar letters. For my case it is returning all values, even those not related to the 3 letters already typed. My question is:
How to send my search.php file the value inside the input so it should know what to search for. For the moment it searches for everything. I checked the value that was going to php and it was empty. Since the query to mysql uses LIKE '%VARIABLE%' and the variable is empty it searches for '%%' which is all cases.
How can i send the correct informacion from JS to PHP with the simplest form.
Here is the explanation :
http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/
Regards