In Spring boot, I'm trying to create another .property file that functions like messages.property, Is that possible? - spring-boot

So I'm trying to create another .property file (called labels.properties) that i can use in Thymeleaf like this:
<div th:text=#{property.from.labels}></div>
Right now I just add labels.properties in the root of resource folder, for now its not working. The purpose of this is I want to separate the property file that handles the error messages from texts for labels & buttons.
Is that possible?
if yes, how to do it?
if yes again, can I do internationalization like adding labels_ja.properties (Japanese)?

You can customize the naming (and location) of the message bundles by configuring the spring.messages.basename property. For example:
spring.messages.basename=labels
By doing so, Spring will look for messages within classpath:labels.properties and classpath:labels_{locale}.properties, such as classpath:labels_ja.properties.
If you want to use this in addition to the regular messages.properties, you can use a comma separated value:
spring.messages.basename=messages,labels
The first one within that comma separated list will take priority over the other ones. If you have a property.from.labels in both messages.properties and labels.properties, the one within messages.properties would be chosen in this example.
This can also be found within the documentation about internationalization.

Related

What NOREPLACE means at netflix's nebula plugin?

I was using netflix's nebula. Looking here, I saw this line:
fileType [org.freecompany.redline.payload.Directive] - Default for types, e.g. CONFIG, DOC, NOREPLACE, LICENSE
I didn't find any doc about the actual meaning of this enum, but I've found the original code.
Now I want an actual description of this enum. I thought NOREPLACE is releated to being not allowed to replace the file. But I want to be sure and don't rely on assumptions.
I have only seen noreplace as an additional attribute on a config file, e.g. %config(noreplace). It means that if the user has edited the file, the installer should put its new version as filename.rpmnew; by default %config files are replaced with the user one put as filename.rpmold .

jstl/jsp print name of file beutiful

I have my tag ${file.name} in a jsp file to display a name of file to download
name containt a full file name,include file extension. for example
testfile.png
a-file.zip
testfile-test505454654.png
a-filenum5468.docx
other_file_with_a_name_very_very_very_larrrrrrrrrrrrrrrrrrrrrge.pdf
Files with very long names, crash my layout.
I think the way to format the file name to shorten it but include the extention. Maybe
testfile.png
a-file.zip
testfile-test505454....png *
a-filenum5468.docx
other_file_with_a_na....pdf *
How I can do?
in href no problem because it is done by id ${file.id}
If file is a POJO, you may add a getter-method to the POJO (something like String getShortName(){}) that returns a short version of the file name. And then use the method in your EL expression: ${file.shortName}.
I would write and register a custom tag that would take care of shortening the output to a maximum length
<custom:short value="${file.name}" var="shortFileName" />
The tag would take care of shortening based on defaults or values you specify in the element and putting it the result in a request attribute you can use anywhere after that declaration.
Since the requirements can be used many times so You should go with CUSTOM Tag solution like #Sotirios Delimanolis suggested.
JSTL function ( Like c:fn ) is another solution. Using jstl function get better performance than Custom tag ( simple / classic model )
Link: http://www.noppanit.com/how-to-create-a-custom-function-for-jstl/

How to build CodeIgniter URL with hierarchy?

I know this doesn't exactly match the form of www.example.com/class/function/ID/, but what I want to display to the user would make more sense.
This is what I would like to do:
www.example.com/project/id/item/item_id/
So, an example would be:
www.example.com/project/5/item/198237/
And this would be the behavior:
www.example.com/project/ --> This would show a list of projects (current implementation)
www.example.com/project/5/ --> This would show a list of items on project 5 (current implementation)
www.example.com/project/5/item/ --> This wouldn't really mean anything different than the line above. (Is that bad?)
www.example.com/project/5/item/198237/ --> This would show details for item 198237.
So, each item is directly associated with one and only one project.
The only way I can think how to do this is to bloat the "project" controller and parse the various parameters and control ALL views from that "project" controller. I'd prefer not to do this, because the model and view for an "item" are truly separate from the model and view of a "project."
The only other solution (that I am currently implementing and don't prefer) is to have the following:
www.example.com/project/5/
www.example.com/item/198237/
Is there any way to build a hierarchical URL as I showed at the beginning without bloating the "project" controller?
There are 3 options, sorted by how practical they can be:
Use URI Routing. Define a regular expression that will use a specific controller/method combination for each URL.
Something like that could help you, in routes.php:
$route['project/'] = 'project/viewall';
$route['project/(.+)'] = 'project/view/$1';
$route['project/(.+)/item/'] = 'project/view/$1';
$route['project/(.+)/item/(.+)'] = 'item/view/$2';
That is, considering your controllers are item and project respectively. Also note that $n in the value corresponds to the part matched in the n-th parenthesis.
Use the same controller with (or without) redirection. I guess you already considered this.
Use redirection at a lower level, such as ModRewrite on Apache servers. You could come up with a rule similar to the one in routes.php. If you are already using such a method, it wouldn't be a bad idea to use that, but only if you are already using such a thing, and preferably, in the case of Apache, in the server configuration rather than an .htaccess file.
You can control all of these options using routes.php (found in the config folder). You can alternatively catch any of your URI segments using the URI class, as in $this->uri->segment(2). That is if you have the URL helper loaded. That you can load by default in the autoload.php file (also in the config folder).

MVC3 localization code generator

I am trying to add two localization resource files into my MVC3 App_GlobalResources.
I add Global.resx and then Gloabl.fr.resx. However, only the first one generates code in .designer.cs. The second one just generate an empty file.
Can anybody help me out?
Thanks a lot.
That is how its supposed to work. The .designer.cs class is a strongly typed class so that you can type.
#Global.mystring and it will return a localised (depending on the UICulture) string.
The designer file doesn't actually contain the localised strings, it just contains a bunch of properties which (in turn) return the localised string.. this is why you wouldn't need more than one class.
Perhaps you are trying to find a way of retrieving the resources for different cultures e.g. fr?
You need to set the UICulture to "fr". Either manually or by setting the following element in the web config:
<globalization culture="auto" uiCulture="auto"/>
This would do it automatically based on your browser settings

CodeIgniter reusable message library

I'm using Message library (http://codeigniter.com/wiki/Message/) to display error messages on my site. This is the code that I'm using to display a message:
$this->message->set('error',$this->config->item('error.login'));
Right now I'm storing common messages in my config file (config/config.php) instead of writing the message every time. Is there a better way to do it? The config file is getting very long.
What I'm looking for is a better way to store re-usable text strings.
CodeIgniter's language class is what you're looking for:
CI Language Class
$this->message->set('error',$this->lang->line('error.login'));
A config file is more or less how you'd want to do it. It is simple, clear and light. But just because you are keeping it in a config file, that does not mean you need to keep it in config.php. The Config class allows you to have multiple config files, so have a special one for messages. Heck, you could even have several special ones for languages, and leave the one you are looking for in the config.php file!
$this->config->load( $this->config->get( "language_file_name" ) );

Resources