2

I'm about, with WebForms, to making a vocabulary (for N languages) that I'll share for my all web applications.

Like MyLanguages.cs. Then I'll create static methods to get my words. But I won't to have it for all my applications, just one for ALL (one in memory, not N).

What's the best strategy you can suggest to me?

EXAMPLE

This should be my class :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class Vocabulary
{
    public const string HelloEnglish = "Hello";
    public const string HelloItalian = "Ciao";

    public Vocabulary()
    {

    }
}

and, everywhere in my web applications, I'd like to call :

Vocabulary.HelloEnglish;

Without copying and inherit that class for each web application, which is always the same... a waste of resources... also because it will grow...

Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507
  • 1
    present an example of what it needs to achive and we can help you. – Aliostad Mar 30 '12 at 14:54
  • Not sure exactly what you mean. But can you not create a stand-alone dll that can then be referenced by whatever needs the functionality? – Darren Young Mar 30 '12 at 14:55
  • As I understand Markzzz wants to share one single instance of Vocabulary between many apps on the same machine. – Nikolay Mar 30 '12 at 14:57

5 Answers5

3

I suggest you use Resources and localise them.

Aliostad
  • 80,612
  • 21
  • 160
  • 208
1

Run it as a WCF Windows Service.

Zruty
  • 8,377
  • 1
  • 25
  • 31
0

I would just store it in a database, adding new languages and words would be trivial to do and would not require a recompilation of anything. This lets you be more dynamic with the retrival as well.

Matthew
  • 24,703
  • 9
  • 76
  • 110
  • uhm...not really! every time I need it is a database call! So would be best download them all in once and store it "forever"... – markzzz Mar 30 '12 at 15:02
0

To avoid deployment issues with Window Service you can host this Vocabulary in one of your application (first one started) and all other apps can connect to that host. There are many ways for apps to interoperate with each other - tcp, named pipes (both can be used with WCF), COM and so on. And also you don't have to worry about memory for assembly itself because Windows will share the same instance between all apps, that use this assembly

Nikolay
  • 3,658
  • 1
  • 24
  • 25
0

A class like this would be a chaos to manage in long term.

If you need a class, better approach would be to create an interface IVocabulary, which has property 'Hello'. Implement it for as many languages as you want. You can then keep a singletone class. This class can return an instance of the IVocabulary. You can also have a SetVocabulary(string language) method to change language at runtime.

public interface IVocabulary
{
    string Hello { get; }
}

public class EnglishVocabulary : IVocabulary
{
    public string Hello
    {
        get { return "Hello"; }
    }
}

public class ItalianVocabulary : IVocabulary
{
    public string Hello
    {
        get { return "Ciao"; }
    }
}

public class CurrentVocabulary
{
    private static IVocabulary instance;

    private CurrentVocabulary()
    {
    }

    public static IVocabulary Instance
    {
        get
        {
            return instance;
        }
    }

    public static void SetVocabulary(string language)
    {
        switch (language.ToLower())
        {
            case "english":
                instance = new EnglishVocabulary();
                break;
            case "italian":
                instance = new ItalianVocabulary();
                break;
            default:
                throw new ArgumentException("Language " + language + " not available.");
                break;
        }
    }
}

However, storing languages in database is the best and dynamic approach so far. You may use a similar model for database driven solution.

Niranjan
  • 76
  • 2