This is a migrated thread and some comments may be shown as answers.

Little solution to get all Localization Keys for any WPF Telerik Control

1 Answer 39 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Markus Hopfenspirger
Top achievements
Rank 2
Markus Hopfenspirger asked on 03 Aug 2012, 09:32 AM
Hi,

I'm using Telerik Control now for quite some time and telerik ist doing a great job on enhancing them. I like Telerik Controls a lot! But I live in Germany so I need to have all those nice features with german texts.

To simplify this task I build a very little app. And this App I want to share here, because I see a lot of questions in this direction...

I would like to attach the Code but it is not allowed to attach .zip files here in the forum...
so:

Create a WPF Solution, reference the Your telerik WPF DLLS and add the following Code and you will get all you need in the Textbox to implement in your real CustomLocalizationManager to get the Texts in your language.

MainWindow.xaml

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
 
        <TextBox Grid.Column="1" Text="{Binding Code}" Margin="10" VerticalScrollBarVisibility="Auto"/>
        
        <StackPanel Margin="10">
            <!-- TODO Put here all Telerik Controls to Localize-->
            <telerik:RadTreeView />
            <telerik:RadGridView />
        </StackPanel>
    </Grid>

ManiWindow.xaml.cs
    public partial class MainWindow : Window {
        private readonly MainWindowViewModel _mainWindowViewModel;
 
        public MainWindow() {
            _mainWindowViewModel = new MainWindowViewModel();
            LocalizationManager.Manager = new CustomLocalizationManager(_mainWindowViewModel);
            InitializeComponent();
            DataContext = _mainWindowViewModel;
        }
    }

MainWindowViewModel.cs
    public class MainWindowViewModel {
        public string Code { getset; }
    }

CustomLocalizationManager.cs

    public class CustomLocalizationManager : LocalizationManager {
        private readonly MainWindowViewModel _mainWindowViewModel;
 
        public CustomLocalizationManager(MainWindowViewModel mainWindowViewModel) {
            _mainWindowViewModel = mainWindowViewModel;
        }
 
        public override string GetStringOverride(string key) {
            var defaultText = base.GetStringOverride(key);
            _mainWindowViewModel.Code += GenerateCode(key, defaultText);
            return defaultText;
        }
 
        private static string GenerateCode(string key, string ret) {
            //TODO Change this line to get the Code you need
            return string.Format("   case \"{0}\": return \"{1}\";{2}", key, ret, Environment.NewLine);
        }
    }


Have fun :-)
Markus

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Aug 2012, 06:03 AM
Hi Markus,

 Thank you very much! I've added 3000 Telerik points to your account.

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
General Discussions
Asked by
Markus Hopfenspirger
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Share this question
or