Introduction
This is an enhanced version of LocaleManager version 1. This software is to help solve the problem that resource files in different locale folders can easily go out of sync. It is very easy to use, and can be handed over to translators or to people who are not developers.
Background
When I started to write this tool, it was mainly to manage the *.properties files I have for an Adobe Air project with Flex development. The code added to support *.resx files was very rough and didn't even support Save changes. Also, I didn't do any research on how to work with *.resx files, and simply parsed them as XML files.
This new build fully supports *.resx files. It also allows the user to create a new locale folder by creating a new directory with the files in the base locale directory copied over. Every single little help makes the user's life easier.
Using the Code
I. Read *.resx files by using ResXResourceReader
ResXResourceReader
is very handy, and reads a name and value pair from a *.resx file.
using (ResXResourceReader rd = new ResXResourceReader(path))
{
KeyValuePair kvp = new KeyValuePair();
foreach (DictionaryEntry d in rd)
{
kvp.key = d.Key.ToString();
kvp.value = d.Value.ToString();
}
}
The only issue with ResXResourceReader
is that it is a little bit awkward to get the comments too. An enumerator needs to be used to enumerate each ResXDataNode
in order to get the comments. However, a ResXDataNode
doesn't include the value of the resource. So, we have to read the *.resx file in two rounds: first, get a key value pair as shown in the code above, then use the code below to get the comment.
using (ResXResourceReader rd = new ResXResourceReader(path))
{
rd.UseResXDataNodes = true;
IEnumerator enumerator = rd.GetEnumerator();
while (enumerator.MoveNext())
{
DictionaryEntry d = (DictionaryEntry)enumerator.Current;
ResXDataNode dataNode = (ResXDataNode)d.Value;
KeyValuePair kvp = new KeyValuePair();
kvp.key = dataNode.Name;
kvp.comment = dataNode.Comment;
AddCommentToGrid(file, kvp);
}
}
II. Change DataGrid Cell Style
A DataGrid
's column style and cell style can be changed easily. In the property view for the DataGrid
, DefaultCellStyle
and AlternationRowsDefaultCellStyle
can be used to set the cell styles.
Then, I use the following code to set the highlight color for the base locale columns:
m_grid.Rows[i].Cells[j].Style.BackColor = BaseColumnColor;
m_grid.Rows[i].Cells[j].Style.BackColor = BaseColumnColor;
III. Display All Languages Selection by Using CultureInfo
As in the main page, the user can select a language and create a new locale folder. It is very easy to get a list of all cultures, by using CultureInfo
.
CultureInfo[] allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo c in allCultures)
m_langue.Items.Add(c);
m_langue.SelectedIndex = 0;
private void m_langue_SelectedIndexChanged(object sender, EventArgs e)
{
CultureInfo c = (CultureInfo)(m_langue.SelectedItem);
m_locale.Text = c.Name;
}
History
- 2/20/09 - Initial version to support *.properties files
- 2/26/09 - Added support for *.resx load and view, but not save
- 3/20/09 - Full support for *.resx files. Also added the Create a new locale feature.
- 3/21/09 - Updated download zips
- 3/24/09 - Updated demo
- 7/31/09 - Added LocaleManager_1.3_Executables.zip