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

Dictionary is not being loaded

9 Answers 265 Views
SpellChecker
This is a migrated thread and some comments may be shown as answers.
plusHR
Top achievements
Rank 1
plusHR asked on 07 Jul 2011, 11:22 AM
Hi all, we use the reduce xap option and seen in the forums the following code to register the spell-checker, however the dictionary is still not present, can you advise what is wrong. We are referencing the correct proofing dictionary in the project.


 ControlSpellCheckersManager.RegisterControlSpellChecker(new TextBoxSpellChecker());
            ControlSpellCheckersManager.RegisterControlSpellChecker(new RadRichTextBoxSpellChecker());
            IControlSpellChecker controlSpellchecker = ControlSpellCheckersManager.GetControlSpellChecker(typeof(RadRichTextBox));
            ISpellChecker spellChecker = controlSpellchecker.SpellChecker;
            DocumentSpellChecker documentSpellChecker = (DocumentSpellChecker)spellChecker;
            documentSpellChecker.AddDictionary(new RadEn_USDictionary(), new System.Globalization.CultureInfo("en-US"));

in the App.xaml.cs in "Application_Startup"

Thanks

9 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 12 Jul 2011, 05:17 PM
Hi Paul,

The code you are using is correct. The problem may be appearing, because your current culture is set to something different from en-US. Thus the spellchecker is not using the dictionary you explicitly have loaded.
To fix that, add the following line to your code:

documentSpellChecker.SpellCheckingCulture = new System.Globalization.CultureInfo("en-US");

If that doesn't help contact us again, so we can investigate further. Best wishes,
Andrew
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
plusHR
Top achievements
Rank 1
answered on 13 Jul 2011, 09:34 AM
Thanks that sorted it. We have downloaded the en-GB TDF files. If we create a separate assembly to load the TDF does this have to be a standard c# or Silverlight class library. When I try to inherit the RadDictionary it is not found even though I reference the Telerik.Windows.Document.Proofing dll. We also use reduce application xap using library caching so would we need to make any changes to the class. Do you have an example?

Thanks
Paul
0
Andrew
Telerik team
answered on 14 Jul 2011, 07:28 AM
Hello Paul,

We are glad that this solved your problem, in a way. So now, to your next questions. 
You can create another assembly similar to Telerik.Windows.Documents.Proofing.Dictionaries.En-US which loads dictionary you have chosen. To do that you have to create a Silverlight Class Library project. Add the .tdf file, set its Build Action to Resource and Copy to Output Directory to Copy if newer.
Now the only thing you have to do is to create a class which inherits from RadDictionary, which in turn implements a method that loads the .tdf file. The following code shows how to achieve that for a German dictionary.

[WordDictionaryMetadata("de-DE")]
    public class RadDe-DEDictionary : RadDictionary
    {
        public RadDe-DEDictionary()
        {
        }
 
        protected override void EnsureDictionaryLoadedOverride()
        {
            Stream stream = Application.GetResourceStream(new Uri("RadDe;component/de-DE.tdf", UriKind.Relative)).Stream;
            this.Load(stream);
        }
    }
Thus you are ready with the creation of the assembly.

For the MEF to be able to discover this assembly you need to do one more thing. You should add the following line to the Application_Startup eventhandler.
RadCompositionInitializer.Container = new CompositionContainer(new SafeXapCatalog());

Now you are good to go. When you add a reference to that assembly in your project and set the SpellCheckingCulture to "de-DE" for example, this .tdf file will be used for spellchecking.

Some side notes:
1. RadDictionary resides in Telerik.Windows.Documents assembly in Telerik.Windows.Documents.Proofing namespace.
2. To use the WordDictionaryMetadata attribute in your Silverlight Class Library project you have to add a reference to System.ComponentModel.Composition

If this doesn't help you, contact us again. Best wishes,
Andrew
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
plusHR
Top achievements
Rank 1
answered on 14 Jul 2011, 09:38 AM
Thanks, however I cannot find where the following is located;

RadCompositionInitializer.Container = new CompositionContainer(new SafeXapCatalog());

Regards
Paul

0
plusHR
Top achievements
Rank 1
answered on 14 Jul 2011, 11:44 AM
Sorted it, I didn't need that line. I signed the assembly and created an extmap.xml file and reference it from the main application and it works nicely. Thanks Paul
0
Tarun
Top achievements
Rank 1
answered on 24 Aug 2011, 09:39 AM
Hi,

How do i avoid writing anything in the  Application_Startup eventhandler.

My scenario is such that, i have created custom controls in a library. And, i have implemented the IControlSpellChecker interface.

Also, added the different .tdf files to the same library (as suggested).

Now, how do i use the CustomDictioanries (from the same assembly)?

I dont want to write the RadCompositionInitializer in every SilverLight application that i create. Is it possible to refernce it from within the custom controls dll.

Paul,
Can you please tell how did u achieve this ?
0
Iva Toteva
Telerik team
answered on 29 Aug 2011, 04:44 PM
Hello Tarun,

In that case, you can add the line from Paul's snippet in the constructor of your custom control, just before the InitializeComponent invocation like this:

public SpellCheckingControl()
{
    RadCompositionInitializer.Container = new CompositionContainer(new SafeXapCatalog());
    InitializeComponent();
}
All the best,
Iva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Tarun
Top achievements
Rank 1
answered on 08 Sep 2011, 08:06 AM
Hi Andrew,

Referring to your response (Posted on Jul 14, 2011), i did exactly the same things.

- Created a Silverlight Class Library project.
- Added .tdf files to that (set the Build action and the Copy to output Directory).
- Created class inheriting from RadDictionary.
- Added the WordDictionaryMetadata attribute with proper Culture.
- Added the CompositionInitializer line.
- And finally, set the SpellCheckingCulture.

But, when i dynamically change the SpellCheckingCulture, i dont see the respective dictionaries getting loaded.

Everytime, the spellchecker is using the default english language.
I have tried to get the spellCheckingCulture just before calling the RadSpellChecker.Check() method also. It says the SpellCheckingCulture is set to whatever i set to. But still, it is not able to load the respective dictionary.

Am i missing something ?

One more point:
If, instead of setting the spell checking culture, i set the Thread.CurrentThread.CurrentUICulture, then in that case, it is loading the respective dictionary.

Isn't it possible to set the language (for dictionary to use) only for SpellChecker (as in asp.net spellCheck) ??

Please respond asap.

Thanks



0
Iva Toteva
Telerik team
answered on 08 Sep 2011, 05:26 PM
Hi Tarun,

The localization language is independent from the spell-checking language.
There is a demo and further explanations of how RadSpellChecker can be used with different languages and how they can be changed runtime here.
More information on localizing RadControls for Silverlight can be found in our online documentation. The list of all strings that RadSpellChecker uses has been published in this forum post.
If you are experiencing any difficulties, we would appreciate some more details or a sample project illustrating the issue.

Regards,
Iva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
SpellChecker
Asked by
plusHR
Top achievements
Rank 1
Answers by
Andrew
Telerik team
plusHR
Top achievements
Rank 1
Tarun
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or