MVC3 localization code generator - asp.net-mvc-3

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

Related

How to get the actual Hyperlink element inside the main document part using docx4j

So I have a case where I need to be able to work on the actual Hyperlink element inside the body of the docx, not just the target URL or the internal/externality of the link.
As a possible additional wrinkle this hyperlink wasn't present in the docx when it was opened but instead was added by the docx4j-xhtmlImporter.
I've iterated the list of relationships here: wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationships().getRelationship()
And found the relationship ID of the hyperlink I want. I'm trying to use an XPath query: List<Object> results = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:hyperlink[#r:id='rId11']", false);
But the list is empty. I also thought that it might need a refresh because I added the hyperlink at runtime so I tried with the refreshXMLFirst parameter set to true. On the off chance it wasn't a real node because it's an inner class of P, I also tried getJAXBAssociationsForXPath with the same parameters as above and that doesn't return anything.
Additionally, even XPath like "//w:hyperlink" fails to match anything.
I can see the hyperlinks in the XML if I unzip it after saving to a file, so I know the ID is right: <w:hyperlink r:id="rId11">
Is XPath the right way to find this? If it is, what am I doing wrong? If it's not, what should I be doing?
Thanks
XPathHyperlinkTest.java is a simple test case which works for me
You might be having problems because of JAXB, or possibly because of the specific way in which the binder is being set up in your case (do you start by opening an existing docx, or creating a new one?). Which docx4j version are you using?
Which JAXB implementation are you using? If its the Sun/Oracle implementation (the reference implementation, or the one included in their JDK/JRE), it might be this which is causing the problem, in which case you might try using MOXy instead.
An alternative to using XPath is to traverse the docx; see finders/ClassFinder.java
Try without namespace binding
List<Object> results = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//*:hyperlink[#*:id='rId11']", false);

OS X Data file editor saving to XML: Document based or not?

So I'm trying to make a data editor for an iOS/Android app I've got. There's 3 separate data files that I'd like to be able to edit, and I would like to save them to plist files or xml files. I'm planning on using Core Data in the app. The problems I'm running into:
1). Should this be a Document-Based Application or not?
2). If so, how would I set it up to allow editing of 3 different structures of files?
3). And if so, how would I go about setting the document based app to use regular plist/xml files as the file type instead of some custom file type?
The plan is for the editor to be able to open up and edit the files, and then the saved files can be copied into the project resources of the iOS and Android apps.
1. Should the app be document-based?
Yes.
2. How would one allow editing three different structures of files?
Choose from any of the following:
Create three dictionaries in the document types list, all three of which reference the same document class.
The same as above, but with windowNibName or makeWindowControllers choosing the UI depending on the document type. In other words, shared model code, but different view hierarchies. (I probably would choose either of the alternatives instead.)
Create three document type dictionaries, each of which has its own document class.
Which one you choose will depend on just how different the types are.
You'll probably want to export a UTI for each document type, as well. Xcode will not help you there; you'll need to write each UTI dictionary by hand.
3. How would I set the document based app to use regular plist/xml files as the file type instead of some custom file type?
If you export one or more UTIs, you should set the parent UTI(s) of each UTI appropriately, but that's advisory; all it means is you'll be able to open the documents with generic plist or XML editors/viewers.
Reading in and writing out the data is up to you, in each document class. You will have to use NSPropertyListSerialization, NSXMLParser, PRHXMLParser, NSXMLDocument, or something else, as you see fit; NSDocument does not handle your file format for you.

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).

How to use Html.Partial() method to render partial view with an explicit path

Everyone, I'm using MVC 3 (Razor). I have the following problem:
I have some common contents segregated into a partial view. But rather than to put it in the default location (views/shared or views/controller-name), I need to put it in a different location (views/shared/new-folder or view/controller-name/new-folder).
I tried this : #Html.Partial("views/shared/new-folder/partial-view-name") or even #Html.Partial("views/shared/new-folder/partial-view-name.cshtml"),but it seems that MVC3 only consider the parameter as a view name, and it totally ignored any path information.
Maybe I did something wrong ,can anybody help me with this ?:) Thank you very much!
You need to reference using an application virtual path (notice the ~\ at the beginning of the path):
#Html.Partial("~\\views\\shared\\new-folder\\partial-view-name.cshtml")
If you have also configured an action to return that Partial View, You could also do:
#{ Html.RenderAction("PartialViewAction", "PartialViewCOntroller");}
This is probably better since you shouldn't be hard coding references to Views in your code. Deploying a hard coded reference on a different server could break the application, but calling an action to return a view won't.

How to add components in to an existing GUI created by guide?

I just created a GUI using guide in MATLAB for a small project I'm working on. I have amongst other things two text fields for from and to dates. Now I'd like to get rid of them and use a Java date select tool. Of course this is not possible using guide so I need to add them manually.
I've managed to get them to show up by putting this code into my Opening_Fcn,
uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
using UICOMPONENT.
But even though it shows up I can't access the date select's attributes, for example
get(handles.til2)
returns
??? Reference to non-existent field 'til2'.
How can I fix this?
Unless you edit the saved GUI figure, the basic handles structure will not include your new component by default.
One way to access you component is to store the handle via guidata, by adding the following to your opening function:
handles.til2 = uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
guidata(hObject,handles)
Functions that need to access the handle need the line
handles = guidata(hObject)
to return the full handles structure that includes the filed til2

Resources