built-in language change doesn't work at Grails2 - grails

I have Grails 2 application where I've already added i18n/messages_ru.properties. So, according to documentation I use request ?lang=ru (f.e. userOperations/index?lang=es) but nothing changed. Languages is still default, lang cookies wasn't created.
What's wrong? How can I fix it up?
PS. I use Oracle Java7 on Ubuntu

What are you expecting to change? If you look at the default index page (the one that lists controllers, etc) it doesn't use messages - it's all hard-coded.
I just tested and it works for me in 2.0.3. Here is what I did:
Create new Application
Create domain class with single field (String name)
Run "Generate All" for that class
The gsp's created will have something like this:
<g:message code="yourDomainClass.name.label" default="Name" />
Now if I don't do anything and look at the page, even with lang=ru or lang=es it is STILL going to say Name. But then I went in and added to the messages_es.properties file the following:
yourDomainClass.name.label=Nombre
and when I refreshed the page it says "Nombre" instead of "Name."
There are defaults in the message files for certain messages like "default.home.label" and when I used the lang=es those did change to Spanish like they should without me doing anything.

The problem is that you configured url(or it was default "/"(view:"index")) mapping to render view directly without a controller. Create a controller and render a view in it. Without a controller it doesn't work!

Related

Automatically populating default issue fields?

We are working on transitioning to Zephyr for JIRA from HP QC/QTP; but a tiny wiggle has presented itself:
When creating a new issue from a test run; the tester has to manually enter version info for the new defect, which on its own is fine, but it's an additional step, and on occasion forgotten.
What we would like then, is for the field "Affects Version/s" to be automatically filled based on either the state of the project, or the sepcific values set in fields in the test.
How can this be achieved?
Allright. You can add custom javascript to JIRA by going to JIRA Administration -> System -> User Interface -> Announcement Banner.
The easiest way is to add a tag linking to your javascript file (wherever it is, must be available to all users. Preferably on the same server as your JIRA installation or a public domain).
Example:
<script type="text/javascript" src="http://YOUR_JIRA_SERVER/includes/custom/javascript/custom.js"></script>
If you add it like above, go into your JIRA installation into the atlassian-jira/includes/ folder and add a folder called custom within which you add another folder called javascript and create a file called custom.js.
In that file, add the following code:
AJS.$(document).ready(function()
{
AJS.$(document.body).on('change', '#issuetype-field', function()
{
var issuetype = AJS.$(this).val();
if(issuetype === "Test") //Might want to change this!
{
AJS.$("#fixVersions").val(17403); //Might want to change this!
}
});
});
This will add an eventlistener to the issuetype-field input found in the create modal window in JIRA. When it changes (which it automatically does on load, then on every user select) it check its value to see if it's Test and if so changes the fixVersion input to a whatever you want to set it to (change this to match your own preferences).
Using jQuery with jira is a bit tricky, you need to use the AJS object to access the jQuery object (more information here: https://docs.atlassian.com/aui/latest/docs/applicationHeader.html).
The two parts you need to change are the actual names and values of your issuetype and your fix version (use firebug or your browsers equivalent to get this).
I've tried this and it worked well! Good luck!

Trying to pass an argument/variable into an attribute in Rails

Imagine I have two models for a Greeting Card App: Template and Card. In creating a Card you specify the target's name, age, and which template you want to use (Card belongs_to template). The Template just has say title and body:text attributes.
I would obviously like there to be a placeholder for the target's name (and perhaps age) within the template body, because I want anyone to be able to create a Card, select the template, and see a Card with the chosen template using their target's name. Is there a way to pass in an argument to the body of the Template for the target's name? I have the Card and target info waiting in the controller but I don't know how to pass it the info since in creating the Template the body was typed into a form and is hard coded into the db as an attribute.
The only way around this I see would be to create a view for each Template instead of storing them in the database, or to create several 'chunks' of the template body, and insert the target's name in between. I'd like to figure this out the more efficient way. Thanks in advance!
If you did not want to do this as templates and truly want it store in the db then I would use javascript to replace keys embedded into the text.
This would also offload the search and replace to the client.
I found the easiest way to go about this ended up just using a designated keyword in the attribute and then replacing it in the controller using the ruby method .gsub!

Maintain parameter info in the request path for all pages instead of the subdomain

I seek some guidedence here ... ( I'm not sure if this is the best title )
At the moment I prepend a "server name" to the url like this:
server10.example.com
This works fine, except that I need to handle all the subdomains on the IIS and I'm not sure google are happy about jumping around from sub to sub to sub, when it seems the links to the other servers.
I'm kind a hoping for a nice way to archive this wioth asp.net mvc.
Most pages are related to a "server" ... there are however a few info pages, contact, home that dont really need a valid "server" name ... but could just be "na" for not available, but the name need to be maintained, if there is already a selected server, when a user are keeps browsing the site. This needs to be as transparent as possible when I need to create the links to the diffenrent pages.
I could extend the Html Action() extensien to automatically add the selected "server" from the previusly request to the page.
In the format:
/{serverParameter}/{controller}/{action}/{parameterInfo}
And if no server is selected, just add "na" as the {server} placeholder.
I'm not sure if more information is needed, but please let me know if ...
I tired of extracting the selected server from the domain part and the other way also seems better, I just can't think of a good way to structure this ...
Updated
90% of all the pages are about a server that the user select at some point. Could be server10, server9, server20 ... just a name. I want to maintain that information across all pages, after the users has selected it or else I just want it to be f.ex: "empty".
I mostly looking for an easy way of doing this or an alternative ... atm I'm prepending the serverParamter to the url so it ends up being: "serverParameter.example.com".
I want to end up with something like
http://example.com/{server}/{controller}/{action}
instread of
http://{server}.example.com/{controller}/{action}
If I understand your question correctly, you just wish to group different collections of content together above the controller/action level. If that's the case, have you considered using ASP.NET MVC areas?
Just right-click on your project, and choose Add -> Area.... Give it a name (what you're calling "server"), and then you can add content, your own controllers, actions, etc. Under this area. You will automatically be able to access it via /AreaName/Controller/Action/etc.
I went with the already impemented routing in ASP.NET MVC.
{server}/{controller}/{action}
When creating the links it takes the set value for {server} and places the value when generating URL's, so I only need to supply controller and action in the #Html.Action helper method ... this could not have been more easy.
I'm not sure why I did not think about this. One just gotta love routing.

Modifying error messages for Command Objects embedded in controller

I am trying to modify the messages.properties file for form input validated by a Command Object that is in specified in the controller. The output I get from the standard error message (that I modified slightly to assure I was hitting that specific one) is:
email cannot be empty test class com.dashboard.RegisterController$DashboardUserRegistrationCommand
but no variant of com.dashboard.RegisterController$DashboardUserRegistrationCommand.null.message
works
I am wondering what the correct specification should be.
Try to put DashboardUserRegistrationCommand outside (below) of RegisterController but still in the same file. Then com.dashboard.DashboardUserRegistrationCommand.. should work.
i.e. com.dashboard.DashboardUserRegistrationCommand.message.nullable
The typical layout of error messages is:
${packageName}.${className}.${propertyName}.${errorCode}
So for your example it would be:
com.dashboard.DashboardUserRegistrationCommand.message.nullable
In the Grails Reference on the right hand side there is a header titled 'Constraints'. On each page of the specific constraints listed under that header the ${errorCode} value is listed at the bottom of the page.
And sometimes you have to restart a run-app to get new messages to populate in a Grails project.
Just to help others in the future, I had the same issues and my problem was the way I was defining my key, I use now:
For default messages:
default.null.message=Write a value for {0}
For commmand error messages:
my.package.UserCommand.name.nullable=Please tell us your name
It is strange that sometimes you use nullable and sometimes you use null. The best thing is going to the Grails Constraints directly and check how is it done for example:
http://grails.org/doc/latest/ref/Constraints/nullable.html

Symfony 1.4 and global variables

I've got a very old php application (1999) that has been worked on during the last ten years. At this point the app starts to show it's age so i'm in te progress of migrating to a "new" framework, symfony 1.4. But since the app is very large, i cannot do this at once. So i'm planning to wrap the old app into the new symfony app, and convert functionality by functionality.
First step in this transition was making the old app appear in the new symfony app. So, i've created the "frontend" application, added a "legacy" module, made it the default homepage, and i've put everyhting i had in my index.php (all pages went through this index.php) in the indexSuccess.php file for the indexAction. I've added the code in the "view" because there are also functions in it and changing that setup would take me more time than i want to spend on the old app.
Unfortunately i've now got an issue with global variables. Let me give you an example (i would have never made this register function like this, but it is, so please look past that.
$session = new ps_session;
$demo = "this is a demo variable";
$session->register('demo');
In ps_session i have this method
public function register($var) {
global $$var;
$_SESSION [$var] = $$var;
}
So it should put the content of $demo in a session var named "demo". Clever right :) Anyway, var_dumping shows me the that $$var is "null" and $demo is filled if i var_dump before and after calling the function. Exact same code without symfony and it returns the correct content.
What am i missing? The global call is spread out in all area's of this massive app so i really don't want to switch to something else, so i'm hoping for a quick fix :)
Maybe relevant, the all code except the index.php content are in frontend/lib/legacy/ folder, the index is in frontend/modules/legacy/ (if there is some scope issue i'm missing)
I think that since your indexSuccess.php file is included inside a function (more precisely, here : lib/vendor/symfony/lib/view/sfPHPView.class.php:185 ), this can't work, because $demo is no longer in the global scope. I don't see any easy workaround for this...
I think you should create a legacy folder in /web , and use routing to redirect to it if the url corresponds to something not migrated yet.
I went with putting the entire old site under web/legacy and redirecting from the default index action to the legacy folder. Most of the url's were made by mod_rewrite so easily fixed. The other url's went through a function so fixing was ok, and only a few were hardcoded. To make it totally transparant, i only need to redo the homepage to start from, so i don't have a visible /legacy/ in my url. Thanks for the help!
I agree with greg0ire that this is an issue with the way sfPHPView includes indexSuccess.
Could you simply require index.php in the default/index action?

Resources