Localisation in the same locale? - cakephp

Depending of a the context of use, I need to “translate” some words in the same locale.
An example :
in context1, the word “team” is translate as "team"
in context2, the word “team” is translate as "group"
in context3, the word “team” is translate as “troop”
What is the best way to do that with the localisation functions of cakephp 3 ?
I can use :I18n::setLocale('context1'); ?
Thanks

Don't change locale for context. The locale always refers to the current translation. Context is a language problem.
From the manual:
Sometimes translations strings can be ambiguous for people translating them. This can happen if two strings are identical but refer to different things. For example, ‘letter’ has multiple meanings in English. To solve that problem, you can use the __x() function:
So you would write:
echo __x('as team', 'team');
echo __x('as group', 'team');
echo __x('as troop', 'team');
CakePHP will write a message to the translation file to indicate what the context is.
https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#using-translation-functions

Related

Naive rule-based machine translation

In order to develop a translation system for a constructed language, I am looking for a method that is easy to implement. I turn quite naturally to algorithms based on rules encoded by an "expert".
Thus, I am looking for references (codes, explanatory documents...) about naive translation algorithms; for example those from the 60s.
Note: I know that the results will probably be rough.
Looking and working with translations, use books and dictionary, and a leguaje as reference, by example from book Moby Dick:
"Call me Ishmael. Some years ago—never mind how
long precisely-having little or no money in my purse, and nothing particular to
interest me on shore, I thought I would sail about a little and see
the watery part of the world."
I need translate spanish text:
"¿Que paises forman parte del mundo?"
When you use a section "with statistically more words and synonyms and antonyms" in text, called "window or scope" this section star with a direct translation word with dictionary and end section, in this example, and search same section in spanish book
start : call -> Llamame. => end: world -> mundo
after processing you result is like to:
how many places about of the wold
You could find more information here

Q: How to handle more than one condition in a UML state machine transition

How do I handle more than one condition (with different boolean expressions) in a UML state machine transition (as guard)?
Example:
In this example I would like to add more than only one condition (Tries < 3) in the transition from "logging in" to "Logged In" like discribed in the note.
How to handle this UML compliant?
Simply spoken (and to focus on the needed step)
put a boolean condition like above in the Guard. This can be any text. You can write C-style or plain text. I'm not sure about OCL here, but that's for academic purpose anyway (my opinion).
N.B. Your diagram shows Tries = 3 which should be a Guard also (i.e. [Tries = 3]) rather than a Name.
There are a couple of options here:
Your guard condition can combine multiple checks within the '[]' - much like you were doing in the note.
You can have multiple transitions between the same two states, each with its own condition.
You can have states within states. So in your example the three states could be within a superstate of 'Normal Operation' - which you then further define in other documentation or via a note.
All of these are valid UML syntax. But note that just because something is valid doesn't mean it will be supported in your editor. For example it was many years before most of the features of sequence diagrams became available within editors...

VIM syntax: conditional function coloring

I'm customizing the standard "c.vim" syntax file in order to tune the visualisation of my C code.
I would like to distinguish the color of the "called functions" from the one of the "declared functions".
Exemple:
int declared_function()
{
int m;
m = called_function();
return (m)
}
I read in depth the VIM documentation, and millions of forums and google results, but all the solutions I tried didn't work.
To resume, I did this:
I defined a region in a recursive way in order to consider all the code within the braces:
syn region Body start="{" end="}" contains=Body
Then I defined through VIM patterns a general function syntax:
syn match cFunction "\<\h\w*\>\(\s\|\n\)*("me=e-1 contains=cType,cDelimiter,cDefine
I did this because I thought I could combine the two in a "if else" condition in the .vimrc file... but after a whole day of failing tests I need the help of someone, who can tell me if it's possible and how to do it.
Thanks everybody.
You're very close. First, you don't need the recursive definition, but contain all other top-level C syntax elements in it, plus the special group you'll define for called functions:
:syn region Body start="{" end="}" contains=TOP,cFunctionUse
Actually, scratch that, the default $VIMRUNTIME/syntax/c.vim already defines a cBlock syntax group.
Then, define a different syntax group that is contained in the cBlock group.
:syn match cFunctionUse "\<\h\w*\>\(\s\|\n\)*("me=e-1 contained containedin=cBlock contains=cType,cDelimiter,cDefine
Finally, link or define a different highlight group for it, so that it actually looks different:
:hi link cFunctionUse Special
You can put those into ~/.vim/after/syntax/c.vim, so that they'll be added automatically to the default C syntax.

CultureInfo name for each country

I have country list with two letter code like 'US' and and three letter code like 'USA'.
I just want to assign all 239 countries have the locale code like en-US (not es-US).
I tried the iterate on:
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
then:
var country = countries.Where(c => c.CodeIso3 == region.ThreeLetterISORegionName).FirstOrDefault();
it doesnt work, to much override.
how to assign the 239 countries code to with is major(or default) language?
Thanks
There is no way to do that. That is because there is no such thing as default language for many of the countries you have in mind.
For example, US does not have an official language. Although English is used by majority of its citizens, it is not default. The other interesting example would be Switzerland. Its citizens use French, German, Italian and Romansh. None of these is default.
That is the reason why there is no such API.
Edit:
As I said before, in many countries there is no such think as default language. I even gave an example of the country which has more than one major language (German and French). To all of you that still can't understand that this really does not make sense, I will give you a clue on how to guess the most probable language:
Common Locale Data Repository Territory-Language Information
If you still cannot understand why restricting to one language per country is probably not the best of ideas, I give up.

Calling functions from plain text descriptions

I have an app which has common maths functions behind the scenes:
add(x, y)
multiply(x, y)
square(x)
The interface is a simple google- style text field. I want the user to be able to enter a plain text description -
'2*3'
'2 times 3'
'multiply 2 and 3'
'take the product of 2 and 3'
and get a answer mathematical answer
Question is, how should I map the text descriptions to the functions ? I'm guessing I need to
tokenise the text
identify key tokens (function names, arguments)
try and map token combinations to function signatures
However I'm guessing this is already a 'solved problem' in the machine learning space. Should I be using Natural Language Processing ? Plain text search ? Something else ?
All ideas gratefully received, plus implementation suggestions [I'm using Python/AppEngine; I know about NLTK and Whoosh]
[PS I understand Google does this already, at least for the first two queries on the list. I'm guessing they also go it statistically, having a very large amount of search data. I don't have a large amount of data available, so will need an alternative approach].
After you tokenise the text, you need parsing to get a syntax tree of your natural language phrase. Once you have this, you can map the parse tree to a mathematical expression, and then evaluate the expression. I do not think this is a solved problem. I would start with several templates, say the first two, and experiment. The larger the domain of possible descriptions, the harder the task is.
I would recommend some tool for provide grammar/patterns on text like SimpleParse for python http://www.ibm.com/developerworks/linux/library/l-simple.html. As java programmer I would prefer GATE or graph-expression.

Resources