Hi, we have IntraWeb applications where we update various UI texts (e.g. TIWLabel.Caption) based on an account language setting for customers of our system, using our own code in base form(s) and helper components, and this in itself is no problem and has been in place since the first version of our applications many years ago. However, the web pages generated by IntraWeb always has a <html lang="en"> element which is incorrect for our customers that use non-English application languages. Previously this was not much of an issue in practice, but with some recent auto-translate features in modern browsers (e.g. Edge) we have seen some weird effects, where not only fixed texts but also some of those coming from the customer's own data have been modified in the browser compared to their actual values in the HTML page in question. Therefore I would like to set a correspondent of the server controller global property HTMLLanguage per session or form, or find a workaround that allows me to adjust the <html lang="en"> element of the generated web page in a more direct way.
So far my searches with AI, Google and in this forum for this have been fruitless. As an experiment, I tried to change ServerController.HTMLLanguage in the BeforeRender event (although I knew this would not be a preferred solution (and probably not thread safe)) but this turned out not to be possible at all (the property setter threw an exception due to being locked in this event). Would be very grateful for feedback on this issue. Currently using IW version 15.2.49 in production.
If you use templates you can specify the <html lang="xx"> there. If not you can set WebApplication.Language := 'xx' and this language property is taken instead of the default lang="en".
WebApplication.Language is initialized with the same as ServerController.Language (the default) but can be changed during session creation (or at any moment forward, e.g. a user decides to select another UI language explicitly).
The language can be established on servercontroller options also for the entire application . My question is: where can i put the title? by default it's empty tag (<title></title>).
WebApplication.Language was the kind of property I was looking for. As I have tested this I have noticed that the property value does not seem persistent. After setting the property the first time for a session, I successfully get the correct language in the generated page, but when I check the property value again in the next server event handler for the session I see that it is empty again. So I ended up adding code like this to make it work:
Code:
procedure TBaseClientServerController.IWServerControllerBaseBeforeRender(
ASession: TIWApplication; AForm: TIWBaseForm; var VNewForm: TIWBaseForm);
begin
if Assigned(ASession) and (ASession.Data is TMyBaseUserSession) then
ASession.Language := TMyBaseUserSession(ASession.Data).HTMLLanguage;
end;
where HTMLLanguage is a property I added in my base class for our user sessions which is populated with a language code based on settings for the account the session belongs to. This works fine, but I just wanted to check if this is the way it's intended to be used?
Strange. WebApplication.Language should be persistent. I tested it with IW15.4.2 and it is.
Setting it once is enough. After a change all pages for this session will render using this language setting.
Are you sure no other software parts in your project are interfering with it?
Can you create a small testcase showing your issue?
Thanks Jeroen, I'll see what I can do, pretty choked with other tasks at the moment. I am thinking it might either have to do with us using an IW version which is too old, or something to do with options and/or code for session management.
Sorry for the delay, but here is a simple test application created using the new IntraWeb project wizard. If I check the project source (in Edge) after initial load, the language is set for Swedish (sv), but if I click the button, the updated page will revert to English (en), at least in the IntraWeb version I am using. Interesting to know if this is different in newer versions (or if I have missed something).
Running your example in IW15.4.2 just works.
The source after initial load contains <html lang="sv">. After hitting the button the source still contains <html lang="sv">.
Hope this helps.
Thanks for checking Jeroen, confirms the conclusion that this issue is solved in later IW releases! Considering migrating to a new IW version for us involves updating 3rd party components, extensive testing etc., and the limited time I have at the moment, I will probably deploy it with my workaround for now. But I will include a compiler hint that reminds us to check it when we later move to a new IW version.