I have an application, that uses Angular 2 for UI and Spring Boot Rest as a microservice. As a database, I have PostgreSQL.
I want this project to support multi-languages.
I heard that spring has something called i18n, but I don't know how to implement it.
One of my microservice is called categories, and what it does is CRUD operations. The default language is English, but I want to add french. So, if a call is like this:
get: http://localhost:8080/categories?lang=fr
I will get all the categories, where lang = 'fr'
Also, probably I will add a table called static_texts, where I will add words to translate, like: contact, menu, testimonials, etc. And for these words, when a user entered for the first time on site, angular will make a call to java to get all the static words, to save in a session, and to add those into the template.
Like this I see the multilanguage system, but, I don't understand how to implement it into my project. Do you have an example, because I couldn't find anything for what I need?
Thanks!
Spring Boot can manage any number of locales in an application flawlessly. Internationalization is a great way to increase users on a product so there are no limits in terms of how users use your product.
The first and simple solution is to implement a LocaleResolver and LocaleChangeInterceptor for managing some resource files for different languages. you can see this tutorial.
However, this approach depends on the access to the application’s resource files when adding a new supported language or modify the existing message files. In case an end-user is responsible for this job and obviously, this is not an optimal approach.
Hence, the second method shows how to move all of our localized messages to a database. This enables the end-user to add a new language or update existing localized messages at runtime with the help of i18n. In this tutorial you'll see how to use your table for translated texts
Related
Situation
We are rebuilding a web application (winforms), from the ground up. The old application will keep running, when the new one is released. This means that the new application needs to talk to an old database, I can't change anything there. The new application will be build with .NET Core 2.0 MVC.
The old application uses a custom translation database table, based on a language-id and translation-id. Very straighforward.
Problem
The old application made a database call for each translation, over and over again. Because the new application needs to reuse this table, i'd rather have a smarter system. Because of the amount of translations, I don't want to get all data on each page request. I also don't want to make a database-call for each translation.
Idea
My idea is to create a custom HtmlHelper (or dependency injected translation instance, but that might be harder in this situation) which only needs the translation ID. The helper will get the language from a cookie. This way, we can simply use the following code in our views:
#Html.Translate(1337)
What i'd like to achieve, is to use the first Translate-call to scan the RazorView for all Translate-calls (with their parameters). This way, I can use a Dependency Injected Scoped instance to save all the translations to. Which means that I only have to make one database call for each requested view.
Actual question
Does this sound like a good idea, and will this be doable? I searched through the MVC source code, but can't find a way to achieve something like this. The RazorView instance in the IHtmlHelper does not seem to have list of IHtmlHelper's or something...
I just started with Joomla 3.x and I'm writing a component for Joomla v3 which is supposed to create new usergroups for creating 'groups'- the design requirements being:
An organisation may set up a group to offer access to some set of services -including communication but also also other types of services - to their members
(the other services is the reason why I believe the community and forum joomla extensions are not suitable- they mostly focus at fora and social media services, not the services I will implement.)
Other persons/members of the organisation may register to this group, which allow him/her to access these services
ps: it is also possible for person to set up a personal account and get access to the set of services. This person may also join one or more groups at a later stage
How to do code the creating of new usergroups? I noticed a possible suggested solution at How to create custom User Group Programmatically in Joomla 3.x, but I struggle to understand how to use the suggested JTableUsergroup class because of the limited documentation at http://docs.joomla.org/API17:JTableUsergroup(?) Does creating an instance of JTableUsergroup results in the creation of a new customer user group?
Another question: how to add users to a customer usergroup? The only hint I found was at http://api.joomla.org/cms-3/classes/JUserHelper.html - using the method addUserToGroup of class JUserHelper.
Many of the Joomla development concepts are well document but I could not find one for managing custom user groups...
Appreciate your help;-)
First, overall, the best consistent documentation of Joomla APIs is in the docblocks for the classes. Then to be honest what I do a lot of times is to search for where in the core the API is used. There are some great pieces of narrative documentation in the wiki, but on the whole I always start with the docblocks which are very complete. However in this case it's pretty simple.
You need to do something along the lines of
$newrow = JTable::getInstance('Usergroup');
//code to add your data
$newtable->save(); // Shortcut for check, bind, store
However, if I were you I would look carefully at UsersModelGroup because there are a lot of other things that should normally happen in this process such as running the user plugins. So I might include and extend that model (which manages the table class) rather than going to the table class directly. In fact your whole component might even be able to extend almost all of the users component or it might also be possible that you could do what you want with plugins rather than reinventing the whole thing.
In terms of assigning users to groups that is trickier because of some legacy things in the code. I think the setter followed by a $user->save() ($user being a JUser instance) is probably the way to go when adding to groups. What I probably would do is to write a custom JFormField that would manage opt-in groups because the core usergroup field includes everything. You could extend that and exclude the groups that you want to have only managed by admin.
Based on a specific application (bakery ERP), I need to create a new branch as a general purpose ERP with basic functionality (invoices, orders, work orders, customer communications...).
This new branch must be customizable for each client: print formats, application colors and icons/images, and restricted access to some application parts...
I've read about resource files for text/icons/image customization, but I need some help or alternatives, maybe defining an Interface to provide needed resources.
I use DevExpress components, so, print formats, and forms layout can be customized storing formats and layouts in files. However, main form has to be completely redesigned, and i wonder about the best way to do this. ¿this can be done with a little project containing the main form and implementing an interface providing custom images for buttons and other customizations?
Apart from layout customization, I need to restrict access to some parts of ERP for each customer, but behavior customization will be minimal or nonexistent, so, maybe I can personalize behavior with an xml config file for each customer.
Independently of my ideas, I thank you for any idea or comment about mu purpose: interface customization for each client, and minimal behavior customization. Don't need complex solutions like Workflow Foundation or completely pug-in based development.
If it's only format of prints and screen images, just use resource files or database configurations.
If you need functionality to be changed - use interfaces and inject their implementation via some framework, like MEF, for example.
And your English is good, no need to sorry
I have an application that handles licence registrations for various product. I'm currently re-factoring into a basic MVC framework (not using any of the big ones yet). We have various basic scenario's e.g. someone can make a cc purchase of a product via the website. This fires the create customer, create order, create licence etc objects (basically just db inserts using beans and gateways as I think that is the "standard"?).
Anyway, to handle all this I'm calling a purchaseService.cfc, which validates the various business rules and wraps the persistence(db) layer processes together. That seems to work fine and I thought having a purchaseService cfc contained that process well.
Now we need another, similar process where a key can be "registered" to achieve the same as above. i.e. provide a licence to the customer. (obviously there will be differing rules).
As far as naming conventions go, are there any rules to help decide what to call these service "wrapper" type cfc's. Most of the examples I see are per object, e.g. the user object has a userGateway and userService and don't give examples of cases where we need a wrapper to call multiple objects. Is what I've done ok convention wise using a purchaseService object? (I was going to call it CustomerlicenceOrder.cfc based on the other objects it was dependent on. What will I do with the new requirement? Perhaps create another service object? Called PurchaseByKeyService? Doesn't sound right to me. I have read so much on OO and MVC etc etc but the more I read the more questions I have :)
Thanks
There's certainly nothing wrong with grouping actions into a common service. In fact, it's usually more accepted than just creating standalone services for each domain object.
Read more on the Service Layer pattern if you're interested.
For a relatively simple application, can Webflow be employed to reduce the need to create form controllers? Well, certainly it can, but I guess what I'm asking is: can and should I write an entire application using Webflow for all of the controller / view logic if my goal for doing so is to reduce the amount of code that I write?
I'm struggling my way through the (poor) Webflow documentation and am wondering if it's worth it, or if I should just stick to regular MVC.
The use case for Web Flow is to solve the problem involved with controller logic that spans multiple-page navigation (a pageflow, or wizard). If you don't have to have a form split across multiple pages (or need several small forms to participate in a single transaction), you probably don't need a Pageflow.
Most applications do need this, however. Anything more than simple CRUD stands to benefit.
Pageflows provide a natural cache for the data and can solve problems involved otherwise when using back button navigation and multiple frames/tabs.
If you are thinking about how to store data that needs to live longer than a single request (the common but misguided view is to store in the HttpSession) then you will definitely get something out of Web Flow. If you're not doing anything like that and processing everything at the request-scope then odds are you don't need Web Flow.
Update:
Web Flow can eliminate the need for specialized controller classes to accomplish following a path of page transitions/form updates along a predefined workflow. If you don't need to do this, you can save yourself a lot of configuration/complexity just by using MVC.
SpringMVC and Spring WebFlow can be used together where appropriate - there is nothing odd about that.
If you have a use-case which is simple crud and you think you could easily implement this using SpringMVC then that's probably the right choice.
Note: You could also achieve this in WebFlow too and that neither better or worst.
If you have complicated wizard logic and state management requirements then WebFlow is great plus you get many other features for free like transactions and persistence support (Version-2).