Browse Source

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

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

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

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

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

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
>
<Style TargetType="{x:Type AvalonEdit:TextEditor}">
<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.Value>
<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 @@ -394,6 +394,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
ctl.Text = StringParser.Parse(ctl.Text);
}
this.Text = StringParser.Parse(this.Text);
RightToLeftConverter.Convert(this);
ImageList imglist = new ImageList();
imglist.ColorDepth = ColorDepth.Depth32Bit;

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

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

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

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

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

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

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

@ -15,7 +15,6 @@ using System.Windows.Input; @@ -15,7 +15,6 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Navigation;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
@ -85,6 +84,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -85,6 +84,8 @@ namespace ICSharpCode.SharpDevelop.Gui
public void Initialize()
{
UpdateFlowDirection();
foreach (PadDescriptor content in AddInTree.BuildItems<PadDescriptor>(viewContentPath, this, false)) {
if (content != null) {
ShowPad(content);
@ -197,6 +198,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -197,6 +198,15 @@ namespace ICSharpCode.SharpDevelop.Gui
void OnLanguageChanged(object sender, EventArgs e)
{
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 {

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

@ -189,10 +189,7 @@ namespace ICSharpCode.SharpDevelop @@ -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)}});
if ((AutoLoadExternalChangesOption && file.IsDirty == false)
|| MessageBox.Show(message,
StringParser.Parse("${res:MainWindow.DialogName}"),
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
|| MessageService.AskQuestion(message, StringParser.Parse("${res:MainWindow.DialogName}")))
{
if (File.Exists(fileName)) {
file.ReloadFromDisk();

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

@ -10,6 +10,7 @@ namespace ICSharpCode.SharpDevelop @@ -10,6 +10,7 @@ namespace ICSharpCode.SharpDevelop
string name;
string code;
string imagePath;
bool isRightToLeft;
public string Name {
get {
@ -27,13 +28,18 @@ namespace ICSharpCode.SharpDevelop @@ -27,13 +28,18 @@ namespace ICSharpCode.SharpDevelop
get {
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.code = code;
this.imagePath = imagePath;
this.isRightToLeft = isRightToLeft;
}
}
}

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

@ -2,11 +2,9 @@ @@ -2,11 +2,9 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using ICSharpCode.Core;
@ -17,17 +15,30 @@ namespace ICSharpCode.SharpDevelop @@ -17,17 +15,30 @@ namespace ICSharpCode.SharpDevelop
{
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 {
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()
{
languages = new List<Language>();
List<Language> languages = new List<Language>();
XmlDocument doc = new XmlDocument();
doc.Load(Path.Combine(languagePath, "LanguageDefinition.xml"));
@ -40,10 +51,12 @@ namespace ICSharpCode.SharpDevelop @@ -40,10 +51,12 @@ namespace ICSharpCode.SharpDevelop
languages.Add(new Language(
el.Attributes["name"].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 @@ -59,5 +59,11 @@ namespace ICSharpCode.Core.Presentation
public static ResourceKey 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 @@ @@ -5,15 +5,19 @@
<Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.WindowStyleKey}">
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter Property="FlowDirection" Value="{DynamicResource {x:Static local:GlobalStyles.FlowDirectionKey}}" />
</Style>
<Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.DialogWindowStyleKey}">
<Setter Property="UseLayoutRounding" Value="True" />
<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="ShowInTaskbar" Value="False" />
</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}">
<Setter Property="MinWidth" Value="73" />
<!-- <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; @@ -8,21 +8,11 @@ using System.Windows.Forms;
namespace ICSharpCode.Core.WinForms
{
/// <summary>
/// Description of RightToLeftConverter.
/// Allows converting forms to right-to-left layout.
/// </summary>
public static class RightToLeftConverter
{
public static string[] RightToLeftLanguages = new string[] {"ar", "he", "fa", "urdu"};
public static bool IsRightToLeft {
get {
foreach (string language in RightToLeftLanguages) {
if (ResourceService.Language.StartsWith(language))
return true;
}
return false;
}
}
public static bool IsRightToLeft { get; set; }
static AnchorStyles Mirror(AnchorStyles anchor)
{
@ -53,17 +43,19 @@ namespace ICSharpCode.Core.WinForms @@ -53,17 +43,19 @@ namespace ICSharpCode.Core.WinForms
/// </summary>
static void Mirror(Control control)
{
switch (control.Dock) {
case DockStyle.Left:
control.Dock = DockStyle.Right;
break;
case DockStyle.Right:
control.Dock = DockStyle.Left;
break;
case DockStyle.None:
control.Anchor = Mirror(control.Anchor);
control.Location = MirrorLocation(control);
break;
if (!(control.Parent is SplitContainer)) {
switch (control.Dock) {
case DockStyle.Left:
control.Dock = DockStyle.Right;
break;
case DockStyle.Right:
control.Dock = DockStyle.Left;
break;
case DockStyle.None:
control.Anchor = Mirror(control.Anchor);
control.Location = MirrorLocation(control);
break;
}
}
// Panels with RightToLeft = No won't have their children mirrored
if (control.RightToLeft != RightToLeft.Yes)

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

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

Loading…
Cancel
Save