Browse Source

Add support for right-to-left translations to SharpDevelop.

pull/1/head
Daniel Grunwald 16 years ago
parent
commit
49de1d390d
  1. 60
      data/resources/languages/LanguageDefinition.xml
  2. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  3. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml
  4. 1
      src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs
  5. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OpenWithDialog.cs
  6. 3
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/SelectReferenceDialog.cs
  7. 1
      src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopAboutPanels.cs
  8. 12
      src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
  9. 5
      src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs
  10. 10
      src/Main/Base/Project/Src/Services/Language/Language.cs
  11. 27
      src/Main/Base/Project/Src/Services/Language/LanguageService.cs
  12. 6
      src/Main/ICSharpCode.Core.Presentation/GlobalStyles.cs
  13. 4
      src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml
  14. 38
      src/Main/ICSharpCode.Core.WinForms/Util/RightToLeftConverter.cs
  15. 3
      src/Main/ICSharpCode.SharpDevelop.Sda/Src/CallHelper.cs

60
data/resources/languages/LanguageDefinition.xml

@ -1,35 +1,35 @@
<Languages> <Languages>
<Languages name="English" code="en" page="" icon="uk.png" /> <Languages name="English" code="en" icon="uk.png" />
<!--<Languages name="Arabic" code="ar" page="" icon="Arabic.png" />--> <!--<Languages name="Arabic" code="ar" icon="Arabic.png" dir="rtl" />-->
<Languages name="Brazilian Portuguese" code="pt-br" page="" icon="brazil.png" /> <Languages name="Brazilian Portuguese" code="pt-br" icon="brazil.png" />
<!--<Languages name="Bulgarian" code="bg" page="" icon="bulgaria.png" />--> <!--<Languages name="Bulgarian" code="bg" icon="bulgaria.png" />-->
<!--<Languages name="Catalan" code="ca" page="" icon="catalonia.png" />--> <!--<Languages name="Catalan" code="ca" icon="catalonia.png" />-->
<!--<Languages name="Chinese (BIG5)" code="cn-big" page="" icon="chinalg.png" />--> <!--<Languages name="Chinese (BIG5)" code="cn-big" icon="chinalg.png" />-->
<Languages name="Chinese (GB)" code="cn-gb" page="" icon="chinalg.png" /> <Languages name="Chinese (GB)" code="cn-gb" icon="chinalg.png" />
<Languages name="Czech" code="cz" page="" icon="czech.png" /> <Languages name="Czech" code="cz" icon="czech.png" />
<!--<Languages name="Danish" code="dk" page="" icon="denmark.png" />--> <!--<Languages name="Danish" code="dk" icon="denmark.png" />-->
<Languages name="Dutch" code="nl" page="" icon="netherlands.png" /> <Languages name="Dutch" code="nl" icon="netherlands.png" />
<!--<Languages name="Finnish" code="fi" page="" icon="finnish.png" />--> <!--<Languages name="Finnish" code="fi" icon="finnish.png" />-->
<Languages name="French" code="fr" page="" icon="france.png" /> <Languages name="French" code="fr" icon="france.png" />
<Languages name="German" code="de" page="" icon="germany.png" /> <Languages name="German" code="de" icon="germany.png" />
<!--<Languages name="Greek" code="el" page="" icon="notyetdone.png" />--> <!--<Languages name="Greek" code="el" icon="notyetdone.png" />-->
<Languages name="Hungarian" code="hu" page="" icon="hungary.png" /> <Languages name="Hungarian" code="hu" icon="hungary.png" />
<Languages name="Italian" code="it" page="" icon="italy.png" /> <Languages name="Italian" code="it" icon="italy.png" />
<!--<Languages name="Japanese" code="jp" page="" icon="japan.png" />--> <!--<Languages name="Japanese" code="jp" icon="japan.png" />-->
<Languages name="Korean" code="kr" page="" icon="south_korea.png" /> <Languages name="Korean" code="kr" icon="south_korea.png" />
<!--<Languages name="Lithuanian" code="lt" page="" icon="lithuania.png" />--> <!--<Languages name="Lithuanian" code="lt" icon="lithuania.png" />-->
<Languages name="Norwegian" code="no" page="" icon="norway.png" /> <Languages name="Norwegian" code="no" icon="norway.png" />
<Languages name="Polish" code="pl" page="" icon="poland.png" /> <Languages name="Polish" code="pl" icon="poland.png" />
<Languages name="Portuguese" code="pt" page="" icon="portugal.png" /> <Languages name="Portuguese" code="pt" icon="portugal.png" />
<Languages name="Romanian" code="ro" page="" icon="romania.png" /> <Languages name="Romanian" code="ro" icon="romania.png" />
<!--<Languages name="Russian" code="ru" page="" icon="russia.png" />--> <!--<Languages name="Russian" code="ru" icon="russia.png" />-->
<!--<Languages name="Serbian" code="sr" page="" icon="serbia.png" />--> <!--<Languages name="Serbian" code="sr" icon="serbia.png" />-->
<!--<Languages name="Slovenian" code="sl" page="" icon="slovenia.png" />--> <!--<Languages name="Slovenian" code="sl" icon="slovenia.png" />-->
<Languages name="Spanish" code="es" page="" icon="spain.png" /> <Languages name="Spanish" code="es" icon="spain.png" />
<Languages name="Spanish (Mexico)" code="es-mx" page="" icon="mexico.png" /> <Languages name="Spanish (Mexico)" code="es-mx" icon="mexico.png" />
<Languages name="Swedish" code="se" page="" icon="sweden.png" /> <Languages name="Swedish" code="se" icon="sweden.png" />
<Languages name="Turkish" code="tr" page="" icon="turkey.png" /> <Languages name="Turkish" code="tr" icon="turkey.png" />
</Languages> </Languages>

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -138,6 +138,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
CustomizedHighlightingColor.ActiveColorsChanged += CustomizedHighlightingColor_ActiveColorsChanged; CustomizedHighlightingColor.ActiveColorsChanged += CustomizedHighlightingColor_ActiveColorsChanged;
ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated; ParserService.ParseInformationUpdated += ParserServiceParseInformationUpdated;
this.FlowDirection = FlowDirection.LeftToRight; // code editing is always left-to-right
this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView)); this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView));
textMarkerService = new TextMarkerService(this); textMarkerService = new TextMarkerService(this);

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml

@ -5,6 +5,7 @@
> >
<Style TargetType="{x:Type AvalonEdit:TextEditor}"> <Style TargetType="{x:Type AvalonEdit:TextEditor}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" /> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="FlowDirection" Value="LeftToRight"/> <!-- AvalonEdit does not support RTL, so ensure we use LTR by default -->
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type AvalonEdit:TextEditor}"> <ControlTemplate TargetType="{x:Type AvalonEdit:TextEditor}">

1
src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs

@ -394,6 +394,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
ctl.Text = StringParser.Parse(ctl.Text); ctl.Text = StringParser.Parse(ctl.Text);
} }
this.Text = StringParser.Parse(this.Text); this.Text = StringParser.Parse(this.Text);
RightToLeftConverter.Convert(this);
ImageList imglist = new ImageList(); ImageList imglist = new ImageList();
imglist.ColorDepth = ColorDepth.Depth32Bit; imglist.ColorDepth = ColorDepth.Depth32Bit;

2
src/Main/Base/Project/Src/Gui/Dialogs/OpenWithDialog.cs

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
@ -61,6 +62,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (defaultBindingIndex < programListBox.Items.Count) { if (defaultBindingIndex < programListBox.Items.Count) {
programListBox.SelectedIndex = defaultBindingIndex; programListBox.SelectedIndex = defaultBindingIndex;
} }
RightToLeftConverter.ConvertRecursive(this);
} }
/// <summary> /// <summary>

3
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/SelectReferenceDialog.cs

@ -5,8 +5,8 @@ using System;
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
@ -64,6 +64,7 @@ namespace ICSharpCode.SharpDevelop.Gui
projectTabPage.Controls.Add(new ProjectReferencePanel(this)); projectTabPage.Controls.Add(new ProjectReferencePanel(this));
browserTabPage.Controls.Add(new AssemblyReferencePanel(this)); browserTabPage.Controls.Add(new AssemblyReferencePanel(this));
comTabPage.Controls.Add(new COMReferencePanel(this)); comTabPage.Controls.Add(new COMReferencePanel(this));
RightToLeftConverter.ConvertRecursive(this);
} }
void Translate(Control ctl) void Translate(Control ctl)

1
src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopAboutPanels.cs

@ -69,6 +69,7 @@ namespace ICSharpCode.SharpDevelop.Gui
versionInfoTextBox.TabIndex = 9; versionInfoTextBox.TabIndex = 9;
versionInfoTextBox.Font = WinFormsResourceService.LoadFont("Courier New", 8); versionInfoTextBox.Font = WinFormsResourceService.LoadFont("Courier New", 8);
versionInfoTextBox.KeyDown += new KeyEventHandler(versionInfoTextBox_KeyDown); versionInfoTextBox.KeyDown += new KeyEventHandler(versionInfoTextBox_KeyDown);
versionInfoTextBox.RightToLeft = RightToLeft.No;
Controls.Add(versionInfoTextBox); Controls.Add(versionInfoTextBox);
Dock = DockStyle.Fill; Dock = DockStyle.Fill;

12
src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs

@ -15,7 +15,6 @@ using System.Windows.Input;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Navigation; using System.Windows.Navigation;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
@ -85,6 +84,8 @@ namespace ICSharpCode.SharpDevelop.Gui
public void Initialize() public void Initialize()
{ {
UpdateFlowDirection();
foreach (PadDescriptor content in AddInTree.BuildItems<PadDescriptor>(viewContentPath, this, false)) { foreach (PadDescriptor content in AddInTree.BuildItems<PadDescriptor>(viewContentPath, this, false)) {
if (content != null) { if (content != null) {
ShowPad(content); ShowPad(content);
@ -197,6 +198,15 @@ namespace ICSharpCode.SharpDevelop.Gui
void OnLanguageChanged(object sender, EventArgs e) void OnLanguageChanged(object sender, EventArgs e)
{ {
MenuService.UpdateText(mainMenu.ItemsSource); MenuService.UpdateText(mainMenu.ItemsSource);
UpdateFlowDirection();
}
void UpdateFlowDirection()
{
Language language = LanguageService.GetLanguage(ResourceService.Language);
Core.WinForms.RightToLeftConverter.IsRightToLeft = language.IsRightToLeft;
this.FlowDirection = language.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
App.Current.Resources[GlobalStyles.FlowDirectionKey] = this.FlowDirection;
} }
public ICollection<IViewContent> ViewContentCollection { public ICollection<IViewContent> ViewContentCollection {

5
src/Main/Base/Project/Src/Services/File/FileChangeWatcher.cs

@ -189,10 +189,7 @@ namespace ICSharpCode.SharpDevelop
string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(fileName)}}); string message = StringParser.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.TextEditorDisplayBinding.FileAlteredMessage}", new string[,] {{"File", Path.GetFullPath(fileName)}});
if ((AutoLoadExternalChangesOption && file.IsDirty == false) if ((AutoLoadExternalChangesOption && file.IsDirty == false)
|| MessageBox.Show(message, || MessageService.AskQuestion(message, StringParser.Parse("${res:MainWindow.DialogName}")))
StringParser.Parse("${res:MainWindow.DialogName}"),
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{ {
if (File.Exists(fileName)) { if (File.Exists(fileName)) {
file.ReloadFromDisk(); file.ReloadFromDisk();

10
src/Main/Base/Project/Src/Services/Language/Language.cs

@ -10,6 +10,7 @@ namespace ICSharpCode.SharpDevelop
string name; string name;
string code; string code;
string imagePath; string imagePath;
bool isRightToLeft;
public string Name { public string Name {
get { get {
@ -27,13 +28,18 @@ namespace ICSharpCode.SharpDevelop
get { get {
return imagePath; return imagePath;
} }
} }
public bool IsRightToLeft {
get { return isRightToLeft; }
}
public Language(string name, string code, string imagePath) public Language(string name, string code, string imagePath, bool isRightToLeft)
{ {
this.name = name; this.name = name;
this.code = code; this.code = code;
this.imagePath = imagePath; this.imagePath = imagePath;
this.isRightToLeft = isRightToLeft;
} }
} }
} }

27
src/Main/Base/Project/Src/Services/Language/LanguageService.cs

@ -2,11 +2,9 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Windows.Forms;
using System.Xml; using System.Xml;
using ICSharpCode.Core; using ICSharpCode.Core;
@ -17,17 +15,30 @@ namespace ICSharpCode.SharpDevelop
{ {
static string languagePath = Path.Combine(PropertyService.DataDirectory, "resources", "languages"); static string languagePath = Path.Combine(PropertyService.DataDirectory, "resources", "languages");
static List<Language> languages = null; static ReadOnlyCollection<Language> languages = null;
public static List<Language> Languages { public static ReadOnlyCollection<Language> Languages {
get { get {
return languages; return languages;
} }
} }
public static Language GetLanguage(string code)
{
foreach (Language l in languages) {
if (l.Code == code)
return l;
}
foreach (Language l in languages) {
if (l.Code.StartsWith(code, StringComparison.Ordinal))
return l;
}
return languages[0];
}
static LanguageService() static LanguageService()
{ {
languages = new List<Language>(); List<Language> languages = new List<Language>();
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
doc.Load(Path.Combine(languagePath, "LanguageDefinition.xml")); doc.Load(Path.Combine(languagePath, "LanguageDefinition.xml"));
@ -40,10 +51,12 @@ namespace ICSharpCode.SharpDevelop
languages.Add(new Language( languages.Add(new Language(
el.Attributes["name"].InnerText, el.Attributes["name"].InnerText,
el.Attributes["code"].InnerText, el.Attributes["code"].InnerText,
Path.Combine(languagePath, el.Attributes["icon"].InnerText) Path.Combine(languagePath, el.Attributes["icon"].InnerText),
el.GetAttribute("dir") == "rtl"
)); ));
} }
} }
LanguageService.languages = languages.AsReadOnly();
} }
} }
} }

6
src/Main/ICSharpCode.Core.Presentation/GlobalStyles.cs

@ -59,5 +59,11 @@ namespace ICSharpCode.Core.Presentation
public static ResourceKey WordWrapCheckBoxStyleKey { public static ResourceKey WordWrapCheckBoxStyleKey {
get { return wordWrapCheckBoxStyleKey; } get { return wordWrapCheckBoxStyleKey; }
} }
static readonly ResourceKey flowDirectionKey = new ComponentResourceKey(typeof(GlobalStyles), "FlowDirectionKey");
public static ResourceKey FlowDirectionKey {
get { return flowDirectionKey; }
}
} }
} }

4
src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml

@ -5,15 +5,19 @@
<Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.WindowStyleKey}"> <Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.WindowStyleKey}">
<Setter Property="UseLayoutRounding" Value="True" /> <Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" /> <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter Property="FlowDirection" Value="{DynamicResource {x:Static local:GlobalStyles.FlowDirectionKey}}" />
</Style> </Style>
<Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.DialogWindowStyleKey}"> <Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.DialogWindowStyleKey}">
<Setter Property="UseLayoutRounding" Value="True" /> <Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" /> <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter Property="FlowDirection" Value="{DynamicResource {x:Static local:GlobalStyles.FlowDirectionKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" /> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="ShowInTaskbar" Value="False" /> <Setter Property="ShowInTaskbar" Value="False" />
</Style> </Style>
<x:StaticExtension x:Key="{x:Static local:GlobalStyles.FlowDirectionKey}" MemberType="FlowDirection" Member="LeftToRight" />
<Style TargetType="{x:Type Button}" x:Key="{x:Static local:GlobalStyles.ButtonStyleKey}"> <Style TargetType="{x:Type Button}" x:Key="{x:Static local:GlobalStyles.ButtonStyleKey}">
<Setter Property="MinWidth" Value="73" /> <Setter Property="MinWidth" Value="73" />
<!-- <Setter Property="Height" Value="21" /> height implicit using text height+padding--> <!-- <Setter Property="Height" Value="21" /> height implicit using text height+padding-->

38
src/Main/ICSharpCode.Core.WinForms/Util/RightToLeftConverter.cs

@ -8,21 +8,11 @@ using System.Windows.Forms;
namespace ICSharpCode.Core.WinForms namespace ICSharpCode.Core.WinForms
{ {
/// <summary> /// <summary>
/// Description of RightToLeftConverter. /// Allows converting forms to right-to-left layout.
/// </summary> /// </summary>
public static class RightToLeftConverter public static class RightToLeftConverter
{ {
public static string[] RightToLeftLanguages = new string[] {"ar", "he", "fa", "urdu"}; public static bool IsRightToLeft { get; set; }
public static bool IsRightToLeft {
get {
foreach (string language in RightToLeftLanguages) {
if (ResourceService.Language.StartsWith(language))
return true;
}
return false;
}
}
static AnchorStyles Mirror(AnchorStyles anchor) static AnchorStyles Mirror(AnchorStyles anchor)
{ {
@ -53,17 +43,19 @@ namespace ICSharpCode.Core.WinForms
/// </summary> /// </summary>
static void Mirror(Control control) static void Mirror(Control control)
{ {
switch (control.Dock) { if (!(control.Parent is SplitContainer)) {
case DockStyle.Left: switch (control.Dock) {
control.Dock = DockStyle.Right; case DockStyle.Left:
break; control.Dock = DockStyle.Right;
case DockStyle.Right: break;
control.Dock = DockStyle.Left; case DockStyle.Right:
break; control.Dock = DockStyle.Left;
case DockStyle.None: break;
control.Anchor = Mirror(control.Anchor); case DockStyle.None:
control.Location = MirrorLocation(control); control.Anchor = Mirror(control.Anchor);
break; control.Location = MirrorLocation(control);
break;
}
} }
// Panels with RightToLeft = No won't have their children mirrored // Panels with RightToLeft = No won't have their children mirrored
if (control.RightToLeft != RightToLeft.Yes) if (control.RightToLeft != RightToLeft.Yes)

3
src/Main/ICSharpCode.SharpDevelop.Sda/Src/CallHelper.cs

@ -51,9 +51,6 @@ namespace ICSharpCode.SharpDevelop.Sda
} }
AssemblyParserService.DomPersistencePath = properties.DomPersistencePath; AssemblyParserService.DomPersistencePath = properties.DomPersistencePath;
// disable RTL: translations for the RTL languages are inactive
RightToLeftConverter.RightToLeftLanguages = new string[0];
if (properties.ApplicationRootPath != null) { if (properties.ApplicationRootPath != null) {
FileUtility.ApplicationRootPath = properties.ApplicationRootPath; FileUtility.ApplicationRootPath = properties.ApplicationRootPath;
} }

Loading…
Cancel
Save