One thing I feel lack when it comes to translations are a way to differentiate between strings at different locations.
Currently, Drupal only supports one translation of each "source"-string. But in many languages, words might have different meanings depending on the context.
I have just started thinking about this, but it should be possible to use the function 'debug_backtrace' to something like this:
If this code is added to the t()-function in core, the exact line and file where t('some string') was called from is available to the translator.
$caller = debug_backtrace();
$file = basename($caller[0]['file']);
$line = $caller[0]['line'];
The only thing I fear is that
a) debug_backtrace is a heavy function, and calling it for every t() in drupal would cause a big performance loss.
- But with normal caching this should not be an issue.
b) Many strings that are translated only once today and that are correct, even if they appear many times in many places, must be translated several times.
- This can be handeled by extending the function that does the translation today to something like:
o Get all strings that match 'source'
o If one of these also has a match on module:line - use that
o Or, if we have a match on module - use that and add source + new location + destination to the correct tables
o Or if we only have a match on source - use that and add source + new location + destination to the correct tables
o Or if we do not have a match, return original source and add source + location to the correct tables
I can make a patch for this, but I would like some feedback first, to know if this is something that others agree on.