I have a WindowsForm application having all text(On form labels/buttons/other controls) written in the Norwegian language. I want to convert all text in English using localization. Is there any way in Devexpress where we can convert all text into English without writing the meaning of every text in a resource file manually?
For example:- In the attachment, "Brukernavn" is hardcoded on a label. I want to auto-convert it into English without assigning its value in English-ResourceFile. What should be the approach in Devexpress localization?
I'm not aware of any Devexpress method to do this. A good solution would be to actually do the work of building a localisation file for English which would work like following.
Add a InternationlisationLayer to your application.
This layer
scours the application to locate all Controls you would possible want
to translate.
After finding all Controls you have to match their
Text values to the translated text.
After finding a matching English
text you will have to replace the Text Property on these Controls.
If you want to avoid building a proper Localisation system a far easier solution is explained below.
Make a List of type and fill it with all control texts you want translated.
Translate the strings and add format them as such that you have a Dictionary of type (where Key would be the original text and Value being the translated text).
At application Start get a list of all Controls you want to translate and do something like the following:
public static IEnumerable<System.Windows.Forms.Control> GetAllControlsOfType(this System.Windows.Forms.Control control, Type type)
{
var controls = control.Controls.Cast<System.Windows.Forms.Control>();
return controls.SelectMany(ctrl => GetAllControlsOfType(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
public void DoTranslation()
{
var ctrls = this.GetAllControlsOfTypes(new List<Type>() { typeof(Label), typeof(Button) });
foreach (var ctr in ctrls)
{
var element = dict.FirstOrDefault(i => i.Key == ctr.Text);
ctr.Text = element.Value;
}
}
Related
In Qt Designer I'm creating multiple labels (for instance):
my_label1
my_label2
my_label3
...
my_label n
Then if I want to hide them I do this:
ui->my_label1->hide();
ui->my_label2->hide();
ui->my_label3->hide();
...
ui->my_labeln->hide();
However I would like to define the labels like
my_label[n]
So then I would be able to do this:
for(i=0;i<n;i++)
{
ui->my_label[n]->hide();
}
I read that I can define the widget like:
QLabel* my_label[5];
but is there any way to do the same from Qt Designer?
Thanks in advance!
Finally I decided to do direct assignment:
QLabel* my_label_array[5];
my_label_array[0] = ui->my_label1;
my_label_array[1] = ui->my_label2;
my_label_array[2] = ui->my_label3;
my_label_array[3] = ui->my_label4;
my_label_array[4] = ui->my_label5;
Then I can do for instance:
for(idx=0;idx<6;idx++) my_label_array[idx]->show();
for(idx=0;idx<6;idx++) my_label_array[idx]->hide();
for(idx=0;idx<6;idx++) my_label_array[idx]->setEnabled(1);
for(idx=0;idx<6;idx++) my_label_array[idx]->setDisabled(1);
etc...
Then I was able to perform iterations. I believe is not the cleanest way to do it but given my basic knowledge of Qt is ok for me.
Thank you very much for your answers and your support! This is a great site with great people.
Instead of creating an explicit array, you may be able to name your widgets using a particular scheme and then use QObject::findChildren() on the parent widget to get a list of the widgets you are after.
If you only want to hide widgets, you can put all the widgets you want to hide in an invisible QFrame (set frameShape to NoFrame) and hide them all by calling setVisible(false) on the QFrame. This may cause some unwanted side effects with layouts so you may have to tweak some size policy settings.
In case you are wanting to hide controls so that you can simulate a wizard type UI, you may want to check into QStackedWidget.
I have another dirty workaround for this:
in header file
// .hpp
class UiBlabla : public QWidget {
...
QLabel** labels;
};
in source file
// constructor
ui->setupUi(this);
labels = new QLabel*[10]{ui->label_0, ui->label_1, ui->label_2, ui->label_3,
ui->label_4, ui->label_5, ui->label_6,
ui->label_7, ui->label_8, ui->label_9};
I haven't seen anything in QtDesigner to do that, but there are a couple of relatively easy ways to get that behavior.
1) Simply store the my_labelx pointers (from QtDesigner) in an array (or better, a QVector):
QVector<QLabel*> my_labels;
my_labels.push_back(ui->my_label1);
my_labels.push_back(ui->my_label2);
Then you can iterate through the QVector.
for(int i=0; i < my_labels.size(); ++i) {
my_labels[i]-> hide();
}
// or with QFOREACH
foreach(QLabel* label, my_labels)
label->hide();
There is a little setup needed in terms of adding all the labels to the QVector, but on the plus side you only do that once.
2) Depending on the layout of your gui, you could have all your labels be children of a container object and iterate through the children
Is there an easy way to convert HTML to display in the new Windows Phone 7.1 (Mango) RichTextBox control. I'm mostly concerned about retaining links and images without using a web browser control.
thanks,
Sam
I would use HTML Agility pack to parse the HTML and transform each type of node in the equivalent in the Document namespace: http://htmlagilitypack.codeplex.com/
You need to handle the nested elements and depending of the level of conformity of the HTML, handling bad formatted content can be hard but HA is a good library.
There's a sample in the source code I think.
public void ConvertRtfToHtml()
{
System.Windows.Forms.WebBrowser webBrowser =
new System.Windows.Forms.WebBrowser();
webBrowser.CreateControl(); // only if needed
webBrowser.DocumentText = richTextBox1.Text;
while (webBrowser.DocumentText != richTextBox1.Text)
Application.DoEvents();
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
richTextBox2.Paste();
}
For selective coloring of static content the following suggestion works fine :
Is it possible to seletively color a wrapping TextBlock in Silverlight/WPF
However my content will be generated at runtime.
For ex. if the Content generated is : "A Quick Brown Fox"
Then I need they string "Brown" to be in color Brown and "Fox" to be in color Red
The Keyword-Color list is fixed and available to me at runtime.
I have looked at the Advanced TextFormatting page on MSDN, but it is too complicated for me, also the sample in there does not compile :(
I am looking at creating a custom control which can do this for me. Let me know if anyone has any idea regarding how to go about this.
Thanks in advance.
The idea is explained in your link: Have a property for the text in the custom control. Then scan the text for the words, and create appropriate Runs. In the end, assign them all to the TextBox inlines collection.
In this example I simply used string.Split(). You might miss words if they are split by other punctuation.
Dictionary<string, Brush> colorDictionary;
string text; // The value of your control's text property
string[] splitText = text.Split(' ', ',', ';', '-');
foreach (string word in splitText)
{
if (string.IsNullOrEmpty(word))
{
continue;
}
Brush runColor;
bool success = colorDictionary.TryGetValue(word, out runColor);
if (success)
{
Run run = new Run(word);
run.Background = runColor;
textbox.Inlines.Add(run);
}
else
{
Run run = new Run(word);
texbox.Inlines.Add(run);
}
}
When populating my treeview I would like to use the same images that I use in my toolbar etc which are stored in a resource file.
The treeview seems to on accept images via an image list.
I was thinking of reflecting and adding the resources to an image list on load...
How do you guyz n girlz generally do this?
Just for completeness, that "sledge hammer" approach to add all images from a resource
foreach (var propertyInfo in
typeof(Resources).GetProperties(BindingFlags.Static | BindingFlags.NonPublic)
.Where(info => info.PropertyType == typeof (Bitmap))) {
mainImageList.Images.Add(
propertyInfo.Name,
(Bitmap)propertyInfo.GetValue(null, null));
}
I usually have an image list that I populate using images from the resource file. This can easily be done when initializing the form.
Example (with three images in Resources.resx, called one, two and three):
private void PopulateImageList()
{
_treeViewImageList.Images.Add("one", Resources.one);
_treeViewImageList.Images.Add("two", Resources.two);
_treeViewImageList.Images.Add("three", Resources.three);
}
I'm working on a data migration task, where I have to export a somewhat large Lotus Notes application into a blogging platform. My first task was to export the articles from Lotus Notes into CSV files.
I created a Agent in LotusScript to export the data into CSV files. I use a modified version of this IBM DeveloperWorks forum post. And it basically does the job. But the contents of the Rich Text field is stripped of any formatting. And this is not what I want, I want the Rich Text field rendered as HTML.
The documentation for the GetItemValue method explicitly states that the text is rendered into plain text. So I began to research for something that would retrieve the HTML. I found the NotesMIMEEntity class and some sample code in the IBM article How To Access HTML in a Rich Text Field Using LotusScript.
But for the technique described in the above article to work, the Rich Text field need to have the property "Store Contents as HTML and MIME". And this is not the case with my Lotus Notes database. I tried to set the property on the fields in question, but it didn't do the trick.
Is it possible to use the NotesMIMEEntity and set the "Store Contents as HTML and MIME" property after the content has been added, to export the field rendered as HTML?
Or what are my options for exporting the Notes database Rich Text fields as HTML?
Bonus information: I'm using IBM Lotus Domino Designer version 8.5
There is this fairly unknown command that does exactly what you want: retrieve the URL using the command OpenField.
Example that converts only the Body-field:
http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField
Here is how I did it, using the OpenField command, see D.Bugger's post above
Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String
Dim obj
Set obj = CreateObject("Microsoft.XMLHTTP")
obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", ""
obj.send("")
Dim html As String
html = Trim$(obj.responseText)
GetHtmlFromField = html
End Function
I'd suggest looking at Midas' Rich Text LSX (http://www.geniisoft.com/showcase.nsf/MidasLSX)
I haven't used the personally, but I remember them from years ago being the best option for working with Rich Text. I'd bet it saves you a lot of headaches.
As for the NotesMIMEEntity class, I don't believe there is a way to convert RichText to MIME, only MIME to RichText (or retain the MIME within the document for emailing purposes).
If you upgrade to Notes Domino 8.5.1 then you can use the new ConvertToMIME method of the NotesDocument class. See the docs. This should do what you want.
Alternativly the easiest way to get the Domino server to render the RichText will be to actually retrieve it via a url call. Set up a simple form that just has the RichText field and then use your favourite HTTP api to pull in the page. It should then be pretty straight forward to pull out the body.
Keep it simple.
Change the BODY field to Store contents as HTML and MIME
Open the doc in editmode.
Save.
Close.
You can now use the NotesMIMEEntity to get what you need from script.
You can use the NotesDXLExporter class to export the Rich Text and use an XSLT to transform the output to what you need.
I know you mentioned using LotusScript, but if you don't mind writing a small Java agent (in the Notes client), this can be done fairly easily - and there is no need to modify the existing form design.
The basic idea is to have your Java code open a particular document through a localhost http request (which is simple in Java) and to have your code capture that html output and save it back to that document. You basically allow the Domino rendering engine to do the heavy lifting.
You would want do this:
Create a form which contains only the rich-text field you want to convert, and with Content Type of HTML
Create a view with a selection formula for all of the documents you want to convert, and with a form formula which computes to the new form
Create the Java agent which just walks your view, and for each document gets its docid, opens a URL in the form http://SERVER/your_database_path.nsf/NEW_VIEW/docid?openDocument, grabs the http response and saves it.
I put up some sample code in a similar SO post here:
How to convert text and rich text fields in a document to html using lotusscript?
Works in Domino 10 (have not tested with 9)
HTMLStrings$ = NotesRichTextItem .Converttohtml([options] ) As String
See documentation :
https://help.hcltechsw.com/dom_designer/10.0.1/basic/H_CONVERTOHTML_METHOD_NOTESRICHTEXTITEM.html
UPDATE (2022)
HCL no longer support this method since version 11. The documentation does not include any info about the method.
I have made some tests and it still works in v12 but HCL recommended to not use it.
Casper's recommendation above works well, but make sure the ACL is such to allow Anonymous Access otherwise your HTML will be the HTML from your login form
If you do not need to get the Richtext from the items specifically, you can use ?OpenDocument, which is documented (at least) here: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/
https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html
OpenDocument also allows you to expand sections (I am unsure if OpenField does)
Syntax is:
http://Host/Database/View/DocumentUniversalID?OpenDocument
But be sure to include the charset parameter as well - Japanese documents were unreadable without specifying utf-8 as the charset.
Here is the method I use that takes a NotesDocument and returns the HTML for the doc as a string.
private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null)
{
var server = doc.ParentDatabase.Server.Split('/')[0];
var dbPath = doc.ParentDatabase.FilePath;
string viewName = "0";
string documentId = doc.UniversalID.ToUpper();
var ub = new UriBuilder();
ub.Host = server;
ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId;
if (string.IsNullOrEmpty(sectionList))
{
ub.Query = "OpenDocument&charset=utf-8";
}
else
{
ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList;
}
var url = ub.ToString();
var req = HttpWebRequest.CreateHttp(url);
try
{
var resp = req.GetResponse();
string respText = null;
using (var sr = new StreamReader(resp.GetResponseStream()))
{
respText = sr.ReadToEnd();
}
return respText;
}
catch (WebException ex)
{
return "";
}
}