Incorrectly says translator can't translate from 'X' to 'Y' when remote language mappings are used, because code to check does not invoke mapping.

Patch attached.

Comments

miro_dietiker’s picture

Issue tags: +Needs tests

Uh, ugly.. We need a test for that!

Also you should provide universal format diffs.
Use git checkout an it is the default mode...

mikel1’s picture

StatusFileSize
new935 bytes

Sorry. Is this better?

miro_dietiker’s picture

The format looks fine. Also the code correction.

But you should also extend our tests to make surr this case has test coverage and will never fail again with future updates!
http://drupal.org/simpletest-tutorial-drupal7

mikel1’s picture

StatusFileSize
new519 bytes

I would have, but still learning how to do things. I did the following, but was unable to run it. Installed simple_test but it seems to have problems (pages and pages of errors on the simple test test). I'll have to figure it out over time.

Thanks, by the way, for this most awesome translation module!

berdir’s picture

Hm. Not sure. Depends on the contract of getSupportedTargetLanguages(), does it receive/return internal or mapped language codes?

In e.g. the Gengo translator, we're doing the mapping within that function, so this would result in double mapping (Actually, it looks like Gengo already does double mapping ?!).

So, whatever we do, we need better documentation to define which function receives mapped language codes and which one doesn't.

One way to put it would be to define that we always do the mapping within TMGMTTraslator and the plugin class already receives the mapped language code and only has to work with that.

miro_dietiker’s picture

Yes we should also use different variable/argument names for local and remote languages.
I consider local "native" so in addition to documentatiom we should alwsys add prefix/postfix in case we deal with remote codes.

Berdir you are right, i didn't check in detail if this suggested change is right or wrong.
Thought the test would provide me the relevant aspects to follow.

mikel1’s picture

Good point Berdir. I assumed that since the local/remote translation was managed by tmgmt and not the plugins, that the plugins would not be the ones to deal with it. But I guess either way is good, as long as it's consistent among plugins and documented. I am using tmgmt_microsoft, and it returns the language codes as it gets them from MS (mapped). The same is true of tmgmt_google.

blueminds’s picture

getSupportedTargetLanguages() method should always return local language codes. There is getSupportedRemoteLanguages() which is expected to get language codes as defined by remote system. To make it clear here is the list of methods dealing with language codes and their responsibilities:

Methods to get mapping info:

getSupportedRemoteLanguages() - gets array of language codes in lang_code => lang_code format. It says with what languages the remote system can deal with. These codes are in the remote format.
getRemoteLanguagesMappings() - remote language codes may differ from local so this method should provide pairs of local_code => remote_code.
getDefaultRemoteLanguagesMappings() - we might know some mapping pairs prior to configuring a plugin, this is the place where we can define these mappings.
mapToRemoteLanguage() & mapToLocalLanguage() - I think these are obvious - helpers to map local/remote.

Methods where remote to local mapping occurs:

getSupportedTargetLanguages() - as mentioned, this should always return local language codes. So within this method the mapping should be executed.
getSupportedLanguagePairs() - gets language pairs for which translations can be done. The language codes must be in local form.

Method where local to remote mapping occurs:

requestTranslation() - here the logic to post the job to the translate service is implemented, and so the local language code has to be flipped to remote

Based on the above the provided patch is wrong, as well as google/ms plugins. Gengo somehow follows this, however incorrectly as canTranslate() is attempting to map lang codes again. Berdir, Miro, if you agree with the above concept I will open an issue to revise all plugins and unify the mappings logic.

miro_dietiker’s picture

Generally agree, but..

The things you described should be 100% cristal clear in the in-code documentation.
You should possibly define a @defgroup with @section
http://drupal.org/node/1354#defgroup

Since i'm mobile i dunno if they are already used. But i guess we can always improve it.

Finally after introducing these api's, yes they shpuld be applied to ALL known plugins.
So let's check all of them and create followup issues.

blueminds’s picture

Status: Active » Closed (won't fix)

Closing this as it will be solved conceptually here: https://drupal.org/node/1999024

miro_dietiker’s picture

Status: Closed (won't fix) » Closed (works as designed)

Here, works as designed is the right one. The other plugins wrongly dealing with the API need fixing.