How to translate a dynamic title attribute - localization

I have this kind of translation to make :
<a tal:attributes="href troncon/url;
title string:Cette etape fait partie du troncon ${troncon/nom}"
tal:content="troncon/nom">Canal du centre</a>
You see that I have a dynamic title attribute that I want to be translatable.
I've tried like this :
<a tal:attributes="href troncon/url;
title string:Cette etape fait partie du troncon ${troncon/nom}"
tal:content="troncon/nom"
i18n:attributes="title">Canal du centre</a>
And like this :
<a tal:attributes="href troncon/url;
title string:Cette etape fait partie du troncon ${troncon/nom}"
tal:content="troncon/nom"
i18n:attributes="title"
title="Cette etape fait partie du troncon ${nom}">Canal du centre</a>
But this doesn't work (of course).
Any ideas ?

The result of the tal:attributes call is passed literally to the translation machinery. i18n:attributes matches it's keys against what tal:attributes generates, and if there is a match, the original attribute on the element is ignored (see this I18N article on the Zope 3 wiki.
This means that the result of "Cette etape fait partie du troncon ${troncon/nom}" will be looked up for translation, requiring you to provide translations for each variation of the sentence that can be made with all possible values of troncon/nom.
To get support for proper placeholders in this string you are better off creating a message id in the code that generates the troncon structure and translate it there, presumably in your view. You need:
A message id with the placeholder
Attach the nom value to the message id
Translate this message to the currently selected language
Include the result in your troncon structure
I generally do this is one step:
from zope.i18n import translate
from zope.i18nmessageid import MessageFactory
_ = MessageFactory('yourdomain')
troncon = dict(
...
nom=nom,
nomtitre=translate(
_(u'troncon_nomtitre', default=u'Cette etape fait partie du troncon ${nom}',
mapping=dict(nom=nom)),
context=self.request)
)
Do note that you need a request for the translation function to pick the correct language.

You can always force the translation on context.translate():
tal:attributes="foobar python:context.translate(string, domain='translationdomain')"
http://collective-docs.readthedocs.org/en/latest/i18n/internationalisation.html#manually-translated-message-ids
However, this might be against all best practices.

Related

Java API which return language code from language display name

I have a service which gives the language display name as part of response. I want to retrieve the language code so that I can apply the internationalization for output file.
Expected input : English - United States
Output : en_US
You might use something like that:
Optional<Locale> locale = Arrays.stream(Locale.getAvailableLocales())
.filter(l ->
l.getDisplayLanguage().equals("English") &&
l.getDisplayCountry().equals("United States")
).findAny();
locale.ifPresent(System.out::println);

JQuery/Globalize: Method for finding best matching locale?

As an example I have loaded following locales:
en
de
de-CH
As code: Globalize.load( require('cldr-data').entireMainFor('en', 'de', 'de-CH'));
When I call const globalize = Globalize(locale); without having set locale loaded I get e.g. Error: Cannot find module './de-AT'
This means that I have to choose one of the existing locales:
de-CH -> choose de-CH
de-AT -> choose de
en-Latn-US -> choose en
it -> choose en
Since everybody needs this piece of code I expected this to exist in the library. Could you point me to a proper implementation?

Delete local printer before mapping

I have the following script that maps printers based on AD grouping:
'---------------------------------------------------------------------------------------------
'-------------------------------MAPEAMENTO DE IMPRESSORAS-------------------------------------
on error resume next
'determines the user who just logged on
Set objSysInfo = CreateObject("ADSystemInfo")
Set WSHNetwork = CreateObject("WScript.Network")
'As soon as we tack on LDAP:// and construct an ADsPath we then bind to the user account in
'Active Directory and report back the groups the user belongs to; this can be done simply
'by enumerating the values in the MemberOf attribute.
strUserPath = "LDAP://" & Replace(objSysInfo.UserName, "/", "\/")
Set objUser = GetObject(strUserPath)
For Each objGroup in objUser.Groups
strGroupName = objGroup.CN
'---------------------------------------------------------------------------------------------
'--------------MAPEAMENTO DE IMPRESSORA DO GRUPO UM-------------------------------------------
'Mapeamento de impressoras por grupo definindo a impressora comom padrão para aquele grupo.
Select Case strGroupName
Case "GrupodoAD1"
WshNetwork.AddWindowsPrinterConnection "\\servidor\impressora1"
WshNetwork.SetDefaultPrinter "\\servidor\impressora1"
End Select
'---------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------
'--------------MAPEAMENTO DE IMPRESSORA DO GRUPO DOIS-----------------------------------------
'Mapeamento de impressoras por grupo definindo a impressora comom padrão para aquele grupo.
Select Case strGroupName
Case "GrupodoAD2"
WshNetwork.AddWindowsPrinterConnection "\\servidor\impressora2"
WshNetwork.SetDefaultPrinter "\\servidor\impressora2"
End Select
'---------------------------------------------------------------------------------------------
'==========Adicione seções adicionais de case para cada grupo do AD que tiver.+===============
next
Now I was asked to delete some local printers on user's computers. The above script runs on logon. The condition although states that only certain printers must be deleted (some users take computers home and we do not want to delete their home printers).
Is there a way I can accomplish this using the above existing script? How can I do that and where do I insert the information? Can I delete more than 1 printer using a single script?
For example I know I must delete:
Samsung SCX-6545X Series PCL 6
Samsung SCX-6545X Series PCL 5
Samsung SCX-6545X Series PS
If I have similar names like above, can I use that to delete any printer that matches parts of the name?
Best regards and thanks in advance for your help!
This is a script I found from somewhere once and adapted slightly to delete printers by device name. Please approach with caution, understand it, and adapt it to your needs carefully:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'HP LaserJet P1505'")
For Each objPrinter In colInstalledPrinters
objPrinter.Delete_
Next
I think you could replace the equals clause in the "SELECT" statement to use a "IN" so you could check all the printers and delete them in one hit. Example:
("Select * from Win32_Printer where DeviceID In ('HP LaserJet P1505', 'Printer_2', 'Printer_3')")

What's options are there for localisation in WebWorks?

I'm building a WebWorks version of an Android app that's localised into 39 languages.
At the moment all the localisations are in xml files of key-value pairs, one file per language .
Each language file has about 400 lines (roughly 40k per file).
Users can change the language used in app.
What options are there in WebWorks to solve this kind of situation?
I'd be more than happy to convert the resource files into any other kind of format to make working with it a better experience on the platform.
You could store each language set in a JavaScript file that you include/load as needed. (I've converted the XML data to a "Map" since it is just key/value pairs)
e.g. (just ignore my translations... I just Googled this, I'm by no means fluent in Spanish)
//Spanish File "lang_spanish.js"
var translations = {
"lose_a_turn": "pierde un turno",
"do_not_pass_go": "huele como un camello",
"take_a_card": "tener una tarjeta de",
"you_win_the_game":"sin motocicletas en la biblioteca",
"you_can_not_move":"desbordamiento de la pila puede ser un lugar divertido"
};
In your <head> you can then have a generic script tag, that you just change the source of as needed.
e.g.
<script id="langFile" src="js/lang_english.js"></script>
When you want a different language, just remove this script from the DOM and add your new one. e.g.
function switchLang(langName){
var headTag = document.getElementsByTagName('head')[0];
var scriptFile = document.getElementById('langFile');
headTag.removeChild(scriptFile);
var newScript = document.createElement('script');
newScript.id = 'langFile';
newScript.src = 'js/lang_' + langName + '.js';
headTag.appendChild(newScript);
}
//call with:
switchLang('spanish');
The alternative would be to load all 39 languages by default... but that seems like overkill considering most will only ever want 1 or 2.

Abstract type not valid in Exchange web services FindItem request

I'm trying to use EWS to search a Task folder on Exchange 2010. I'm trying to limit the due dates of the Tasks returned, but unfortunately there's no equivalent to the CalendarView for the Task folder, so I have to use a FindItem search.
I'm using Java, Axis2 and I prepare the query like this:
// fiType is, obviously, a FindItemType
RestrictionType rType = fiType.addNewRestriction();
IsGreaterThanOrEqualToType igtoretType = IsGreaterThanOrEqualToType.Factory.newInstance();
igtoretType.addNewFieldURI().setFieldURI(UnindexedFieldURIType.TASK_DUE_DATE);
igtoretType.addNewFieldURIOrConstant().addNewConstant().setValue(dateFormat.format(begCal.getTime()));
IsLessThanOrEqualToType iltoretType = IsLessThanOrEqualToType.Factory.newInstance();
iltoretType.addNewFieldURI().setFieldURI(UnindexedFieldURIType.TASK_DUE_DATE);
iltoretType.addNewFieldURIOrConstant().addNewConstant().setValue(dateFormat.format(endCal.getTime()));
SearchExpressionType[] seArr = new SearchExpressionType[2];
seArr[0] = igtoretType;
seArr[1] = iltoretType;
AndType aType = rType.addNewAnd();
aType.setSearchExpressionArray(seArr);
Unfortunately, I get this error:
org.apache.axis2.AxisFault: La demande a échoué lors de la validation du schéma : L'élément 'http://schemas.microsoft.com/exchange/services/2006/types:SearchExpression' est abstrait ou son type l'est.
Roughly translated from French, it means that the query failed because the type SearchExpression is abstract, or it's type is.
After searching, I found this article explaining how to modify the types.xsd file to take care of this. However, even after applying the modifications, I still get the same error.
I'm at a loss as to how to go about solving this. Any help would be appreciated.
Another option is EWS Java API by Microsoft...

Resources