How to translate sentences using vuei18n? - vuejs2

Currently I have been able to translate only words, but in the case of wanting to translate an entire sentence, I don't know how to do it.
taking the following example json
{
"Hello":"Hola"
"how":"como"
"You go":"te va"
"text 4": "texto 4"
"text 5: "texto 5"
}
So when entering all the text "Hola como te va texto 4 texto 5", I must get "Hello how do you go text 4 text 5" as translation,but I only manage to do it by words, example:
<p>{{$t("Hola")}}</p>
get in response in the browser 'Hola', indeed

Lucky you, I just learned this about a few weeks ago.
So what you need is actually exist in the documentation. I believe it is called Linked Local Message.
So here's an example for you..
{
"Hello":"Hola",
"how":"comp",
"You_go":"te va",
"text4": "texto 4",
"text5: "texto 5",
"sentence": "#:Hello #:how #:You_go #:text4 #:text5"
}
Then try
$t('sentence')
So it will actually linked to the "Hello" part of your json. So if you only have #:Hello at sentence it will result in Hola. It's kind of hard to read, but it's the syntax.
And if you didn't understood, I just made a fiddle for your experiment related to the feature. It has two languages that is en and test that represent whatever language you use in the example. Here is the link to jsFiddle
Hope it helps, feel free to ask as well :D

Related

Query for substrings from freeform STT input

I have a PostgreSQL database with vocabulary in a table.
I want to receive Speech to Text (STT) input and query my vocabulary table for matches.
This is tricky since STT is somewhat free-form.
Let's say the table contains the following vocabulary and phrases:
How are you?
Hi
Nice to meet you
Hill
Nice
And the user is prompted to speak: "Hi, nice to meet you"
I transcribe their input as it comes in as "Hi nice to meet you" and query my database for individual vocabulary matches. I want to return:
[
{
id: 2,
word: "Hi"
},
{
id: 3,
word: "Nice to meet you"
}
]
I could query with wildcards where word ilike '%${term}% but then I'd need to pass in the correct substring so it'd find the match, e.g., where word ilike '%Hi%, but this may incorrectly return Hill. I could also split the spoken input by space, giving me ["Hi", "nice", "to", "meet", you"], and loop through each word looking for a match, but this may return Nice rather than the phrase Nice to meet you.
Q: How can I correctly pass substrings to a query and return accurate results for free-form speech?
Two PostgreSQL functions could help you here:
to_tsvector: creates a text search list of tokens (lexemes: unit of lexical meaning)
to_tsquery for querying the vector for occurrences of certain words or phrases.
See Mastering PostgreSQL Tools: Full-Text Search and Phrase Search
If that's not enough you need to turn to natural language processing (NLP).
Something like PyTextRank could help (something that goes beyond the bag-of-words technique):
import spacy
import pytextrank
text = "Hi, how are you?"
# load a spaCy model, depending on language, scale, etc.
nlp = spacy.load("en_core_web_sm")
# add PyTextRank to the spaCy pipeline
tr = pytextrank.TextRank()
nlp.add_pipe(tr.PipelineComponent, name="textrank", last=True)
doc = nlp(text)
# examine the top-ranked phrases in the document
for p in doc._.phrases:
print("{:.4f} {:5d} {}".format(p.rank, p.count, p.text))
print(p.chunks)

How to keep translations separated where the same word is used in English but a different one in other languages?

Imagine I have a report, a letter actually, which I need to translate to several languages. I have created a greeting field in the form which is filled programatically by an onchange event method.
if self.partner_id.gender == 'female':
self.letter_greeting = _('Dear %s %s,') % ( # the translation should be "Estimada"
self.repr_recipient_id.title.shorcut, surname
)
elif self.partner_id.gender == 'male':
self.letter_greeting = _('Dear %s %s,') % ( # translation "Estimado"
self.repr_recipient_id.title.shorcut, surname
)
else:
self.letter_greeting = _('Dear %s %s,') % ( # translation: "Estimado/a"
self.partner_id.title.shorcut, surname
)
In that case the word Dear should be translated to different Spanish translations depending on which option is used, this is because we use different termination depending on the gender. Exporting the po file I found that all the options are altogether, that make sense because almost all the cases the translations will be the same, but not in this case:
#. module: custom_module
#: code:addons/custom_module/models/sale_order.py:334
#: code:addons/custom_module/models/sale_order.py:338
#: code:addons/custom_module/models/sale_order.py:342
#, python-format
msgid "Dear %s %s,"
msgstr "Dear %s %s,"
Solutions I can apply directly
Put all the terms in different entries to avoid the same translation manually every time I need to update the po file. This can be cumbersome if you have many different words with that problem. If I do it and I open the file with poedit, this error appears: duplicate message definition
Put all the possible combinations with slashes, this is done y some other parts of Odoo. For both gender would be:
#. module: stock
#: model:res.company,msg:stock.res_company
msgid "Dear"
msgstr "Estimado/a"
This is just an example. I can think of many words that look the same in English, but they use different spelling or meanings in other languages depending on the context.
Possible best solutions
I don't know if Odoo know anything aboutu the context of a word to know if it was already translated or not. Adding a context manually could solve the problem, at least for words with different meanings.
The nicest solution would be to have a parameter to the translation module to make sure that the word is exported as an isolated entry for that especific translation.
Do you think that I am giving to it too much importance haha? Do you know if there is any better solution? Why is poedit not taking into account that problem at all?
I propose an extension of models res.partner.title and res.partner.
res.partner.title should get a translateable field for saving salutation prefixes like 'Dear' or 'Sehr geehrter' (German). Maybe it's worth to get something about genders, too, but i won't get into detail here about that.
You probably want to show the configuring user an example like "Dear Mr. Name" or something like that. A computed field should work.
On res.partner you should just implement either a computed field or just a method to get a full salutation for a partner record.
To some degree this is a linguistics problem. I believe the best solution would be to use a different "Source Language", one made up of keys, and then have English as another Translation. The word "Dear" in English does not have a gender context (and typically, much of English doesn't), while the word "Estimado" in Spanish does. The translation from that Spanish word to English is more appropriately "Masculine Dear." Therefore, using keys as your source language, you would have this:
SourceText (EnglishDescription) -> Translation (English) -> Translation (Spanish)
DearMasculine -> Dear -> Estimado
DearFeminine -> Dear -> Estimada
DearNuetral -> Dear -> Estimado/a

Is there a way to use Soft Assert to be able to verify if the text contains a certain string

I do not want to use Assert as it would be a hard fail in case it does not find a match. So I am looking to use Soft Assert. But in my scenario I need to check if there is a partial text match. Please help.
Thanks,
Divya
Here you can follow the below approach.
Think your actual text is "Business process ID: 123456 has been updated", and you want to check whether it contains only the "has been updated" partial string.
String actual = "Business process ID: 123456 has been updated";
String partial = "has been updated";
softAssert.assertTrue(actual.contains(partial), "partial string is not contained in the given text");
softAssert.assertAll();

Am I training my wit.ai bot correctly?

I'm trying to train my Wit.ai bot in order to recognize the first name of someone. I'm not very sure if I well understand how the NLP works so I'll give you an example.
I defined a lot of expressions like "My name is XXXX", "Everybody calls me XXXX"
In the "Understanding" table I added an entity named "contact_name" and I add almost 50 keywords like "Michel, John, Mary...".
I put the trait as "free-text" and "keywords".
I'm not sure if this process is correctly. So, I ask you:
does it matter the context like "My name is..." for the NLP? I mean...will it help the bot to predict that after this expression probably a fist name will come on?
is that right to add like 50 values to an entity or it's completly wrong?
what do you suggest as a training process in order to get the first name of someone?
You have done it right by keeping the entity's search strategy as "free-text" and "Keywords". But Adding keywords examples to the entity doesn't make any sense because a person's name is not a keyword.
So, I would recommend a training strategy which is as follows:
Create various templates of the message like, "My name is XYZ", "I am XYZ", "This is XYZ" etc. (all possible introduction messages you could think of)
Remove all keywords and expressions for the entity you created and add these two keywords:
"a b c d e f g h i j k l m n o p q r s t u v w x y z"
"XYZ" (can give any name but maintain this name same for validating the templates)
In the 'Understanding' tab enter the messages and extract the name into the entity ("contact_name" in your case) and validate them
Similarly, validate all message templates keeping the name as "XYZ"
After you have done this for all templates your bot will be able to recognise any name in a given template of the message
The logic behind this is your entity is a free-text and keyword which means it first tries to match the keyword if not matched it tries to find the word in the same position of the templates. Keeping the name same for validations helps to train the bot with the templates and learn the position where the name will be usually found.
Hope this works. I have tried this and worked for me. I am not sure how bot trains in background. I recommend you to start a new app and do this exercise.
Comment if there is any problem.
wit.ai has a pre-trained entity extraction method called wit/contact, which
Captures free text that's either the name or a clear reference to a
person, like "Paul", "Paul Smith", "my husband", "the dentist".
It works good even without any training data.
To read about the method refer to duckling.

CSV File Lookup - Objective C

I have a file.csv file with over 180,000 lines in it. I need to pick out only about 8 lines from it. Each of these lines has go the same id so this is what the file would look like:
"id", "name", "subid"
"1", "Entry no 1", "4234"
"1", "Entry no 2", "5233"
"1", "Entry no 3", "2523"
. . .
"1", "Entry no 8", "2322"
"2", "Entry no 1", "2344"
Is there a way for me to pick out just all the data with the id 1 or another numbers without indexing the whole file into a database (Either SQLITE or Core Data) since this would cause major performance issues for the app to have to index 180,0000 records. This is all for the iPhone and is on ios 5.
Thanks for the help.
Just parse the CSV and store the values in local variable. For parsing CSV via Objective-C checkout following tutorial(s):
http://www.macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data
http://cocoawithlove.com/2009/11/writing-parser-using-nsscanner-csv.html
Kind regards,
Bo
I would strongly recommend putting that in Core Data, sure it will be indexed but that is actually a good thing since your lookups will be wayyy faster, parsing that document every time is going to be way more demanding than looking it up in Core Data, the overhead is a small price to pay.
Sounds like a good job for Dave DeLong's CHCSVParser.
It works a bit like NSXMLParser, so you can just skip all the lines you don't want, and keep the 8 lines you do want.