I installed, the bundle: https://github.com/lunetics/LocaleBundle which help to switch between language. Everything works fine, in twig, translation works fine. But when i want to translate any message in the controller, i get french (fr) instead of defined language (en for example).
Please how can i get the current selected locale in the controller ?
i use: $this->getRequest()->getLocale() but it does not work, it give me FR for each culture.
my default setting language in parameter.ini is FR
After looking inside the code of LuneticsLocaleBundle and Symfony 2.1 Documentation, i discovred that, symfony2.1 is passing the Locale in route. The problem exists when rendering an action from twig template, where symfony creates nes request. So, to resolve this, i override the code of LuneticsLocaleBundle and i added $this->get('session')->set('_locale', $_locale); in the switchAction of LocaleController of the bundle.
So, the locale, will be stored in session.
I hope that can helps you too.
Related
Environment:
I'm writing a SPA with JSF2.2, Bootsfaces 0.9.1, Primefaces 6.0, JEE7 and Hibernate 5.2 in combination with MySQL 5.7 DB.
What I have:
My SPA has a navbar on the upper part and a specific menu based on the selection of the navbar on the left. On the right side and under the navbar I've my main "content page". Similar to this picture but with the difference that my menu is dynamic:
For updating the content page I'm using AJAX.
Everything around the navigation is working as I expected as long as my content page does not contain a b:carousel!
What I tried to do:
As I mentioned above my SPA and all navigation is working correctly unless I add a b:carousel to a content page.
Please consider following example:
I got 2 content pages. Page 1 contains a single label with some text. Page 2 contains a b:carousel with some images. Page 1 is the welcome page.
As soon as I navigate from page 1 to page 2 nothing happens. I need to completely refresh the whole page to see page 2 and even this is not working everytime.
My main question:
Is there any trick to update the content page with ajax if there's a b:carousel on it?
What am I doing wrong?
EDIT:
I created a sample project on github so you're able to see what I mean. I used Java 1.8, Tomcat 8.0.36 and Netbeans IDE, however the project is a Maven project an should work in eclipse, too.
Project: https://github.com/mweber96/stackoverflow39128418
SPA Approach I partly used: http://www.beyondjava.net/blog/single-page-applications-with-bootsfaces/
This question is related to my previous question: Use ui:repeat with b:carousel?
It's a combination of two bugs:
Your example at GitHub uses PrimeFaces, but it doesn't seem to use a PrimeFaces component. The effect is that PrimeFaces adds some fancy JavaScript to load the missing CSS files dynamically (which is great!), but it doesn't add the PrimeFaces core library, so Mojarra runs into an exception it silently hides. You can fix this by adding a (possibly hidden) PrimeFaces component to your page, by including the PrimeFaces core.js file directly (although I wouldn't recommend that) or - of course - by removing the PrimeFaces dependency if you really don't need it.
BootsFaces relies on the HTML attributes to initialize the carousel. To my surprise, this even works, at least partially. However, to start the sliding automatically, you still need to initialize the JavaScript widget manually. In your case, that's
$("#myCarousel").carousel();
BTW, I suggest you open a bug on our bug tracker to fix the latter point (https://github.com/TheCoder4eu/BootsFaces-OSP/issues). Thanks in advance!
I use chosen 1.2.0 from nuget. My chosen.css file contains class like .chosen-container, .chosen-container. When i call my dropdownlist class using .chosen() function. Resulted css class will be chzn-container, chzn-container-multi. It causes display ugly. but functionality work. I have no error in browser console.
When i check another sites, both generated markup and chosen.css contains chzn-container, chzn-container-multi classes only.
Nuget adds only css. It is not add chosen.jquery.js. I don't know why.
The Nuget package named simply "chosen" does not, as the OP says, contain the .js.
You need to search for Harvest.Chosen. Hopefully this will help someone in the future.
I have a localized website for different languages
Users can select which language to use in a profile and this will be applied beforePageLoad
using
context.setLocalString("en")
"en" is default to en-US i believe so the dates on the website is displayed in the US format so I learned that I can use instead.
context.setLocale(new Locale("en","gb"))
the problem with setLocal is that is does not update the HTML lang="en" attribute so event though the dates are correct after using setLocal the language file that is used is still the englisn(US) and not the english(uk) one. (i.e not html lang="en-gb")
so when users from england set their language to en-uk in thier profile they get the US language file.
So I tried to do both like this
context.setLocale(new Locale("en","gb"))
context.setLocalString("en-GB")
but then the setLocalString overrides the setLocalString and vice versa. so it looks like I can't use them both
Is there any way I can add code on beforePageLoad to make sure both the html lang attribute gets updated with correct language and my dates dispay in the correct format for the language set?
Instead of using the context object try to set the locale directly in the view root during beforeRenderResponse:
<xp:this.beforeRenderResponse>
<![CDATA[#{javascript:
facesContext.getViewRoot().setLocale( new java.util.Locale("en-GB") );
}]]>
</xp:this.beforeRenderResponse>
Or you can switch the locale in a phase listener as described here:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=xpages-localization-setter
EDIT:
The locale setting is a little bit strange. You have to use an underscore between en and GB when using context.setLocaleString() (as Panu Haaramo answered), but this won't solve problem, because the ViewRootRender uses only the language setting for the generation of the lang attribute while rendering the HTML output.
This
new java.util.Locale("en", "GB").getLanguage()
will return en only, the "GB" is ignored.
Using the context.setLocaleString will bring the same result because this only parses the given string and converts it into a java.util.Locale which returns the same result as descibed.
But using an undefined Locale will generate a lowercased lang attribute. F.e. this
<xp:this.beforeRenderResponse>
<![CDATA[#{javascript:
facesContext.getViewRoot().setLocale( new java.util.Locale("en-Blabla-Blubb") );
}]]>
</xp:this.beforeRenderResponse>
generates the following HTML tag:
<html lang="en-blabla-blubb">
Thats why the code at top of this answer sets the lang attribute to en-gb, but this is still incorrect: It should set it to en-GB as described here: w3.org: Best Practices: Specifying Language in XHTML & HTML Content
Starting with the skeleton application I want to create a multilingual project. For the Navigation I'm using Zend\Navigation. Everyhting works well - not setting a translator for the navigation view helper.
The translator is registered within the module.config.php and works well for all kinds of translations (including translate view helper, also within layout). But to be able to translate labels of the navigation I need to set the translator to the navigation view helper. According to the documentation this could be done like this:
$this->navigation()->setTranslator($translator);
Or something like that. Problem is that I can't find out how to fetch the configured translator from within the layout. Is there a way to access the ServiceManager or getting the service locator?
Instead of setting the translator with the navigation, since it's already configured as you said, you could use TextDomain instead. Here is what I currently do:
$this->navigation('Zend\Navigation\Navigation')->setTranslatorTextDomain('textdomainhere');
Of course if all your translations are in the same textdomain of default, then you don't need to set anything: $this->navigation('Zend\Navigation\Navigation');
As for getting the translate working in the layout all you do is:
echo $this->translate('Translate This Text', 'textdomainhere');
I am working using richfaces 3.3.3 , tomcat 6. when i try to access my application using IE6 and the windows language is set to arabic, i get the following exception:
IllegalArgumentException: Parameter "size" for convert from HTML to java can not be decoded: [1px], reason: Unparseable number: "1px".
when i change the windows language back to english, restart the server and try to log in again everything works fine..
Can anybody please help me with this issue
You have this problem. Unfortunately it seems to be a bug in the NumberFormat class.
I managed to find a workaround: In your rich:tabPanel, add the attribute headerSpacing="1" (without any unit). This will solve the parser problem. Took me quite a while debugging jsf and jdk to find out...
One more thing you need to do: In your skin, set generalSizeFont to a value without a unit. I.e. for example "generalSizeFont=11". Otherwise you will get the exception for icons (they will still work, though).