source: trunk/CrypPluginBase/Miscellaneous/LocExtension.cs @ 2295

Last change on this file since 2295 was 2295, checked in by Sven Rech, 11 years ago

Prepared KeySearcher for Localization

File size: 2.3 KB
Line 
1/*
2   Copyright 2010 Sven Rech
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Resources;
21using System.Text;
22using System.Windows.Markup;
23using System.Xaml;
24using Cryptool.PluginBase.Attributes;
25
26// Register the extention in the Microsoft's default namespaces
27[assembly: System.Windows.Markup.XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "Cryptool.PluginBase.Miscellaneous")]
28[assembly: System.Windows.Markup.XmlnsDefinition("http://schemas.microsoft.com/winfx/2007/xaml/presentation", "Cryptool.PluginBase.Miscellaneous")]
29[assembly: System.Windows.Markup.XmlnsDefinition("http://schemas.microsoft.com/winfx/2008/xaml/presentation", "Cryptool.PluginBase.Miscellaneous")]
30
31namespace Cryptool.PluginBase.Miscellaneous
32{
33    [MarkupExtensionReturnType(typeof(object))]
34    [ContentProperty("Key")]
35    public class LocExtension : MarkupExtension
36    {
37        public string Key { get; set; }
38
39        public LocExtension(String key)
40        {
41            Key = key;
42        }
43
44        public override object ProvideValue(IServiceProvider serviceProvider)
45        {
46            try
47            {
48                IRootObjectProvider service = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
49                var locAttribute = (LocalizationAttribute)Attribute.GetCustomAttribute(service.RootObject.GetType(), typeof(LocalizationAttribute));
50                ResourceManager resman = new ResourceManager(locAttribute.ResourceFile, service.RootObject.GetType().Assembly);
51                return resman.GetString(Key);
52            }
53            catch (Exception ex)
54            {
55                return Key;
56            }
57        }
58
59    }
60}
Note: See TracBrowser for help on using the repository browser.