Custom Control pour gestion du Multilangue
Bonjour,
Vous n'auriez pas une doc sur System.ComponentModel.Component?
Mon objectif est de gérer le multilangue dans une application avec :
- un custom control (que je nomme Connector) qui me permet de me pluguer à un fichier XML comprenant les différentes traductions pour un objet. Exemple :
Code:
1 2 3 4 5
| <?xml version="1.0" encoding="iso-8859-1" ?>
<object id="Label1">
<text lang="Fr"><![CDATA[<b><u>Mon Text en html</u></b>]]></text>
<text lang="En"><![CDATA[<b><u>My html text</u></b>]]></text>
</object> |
- Un custom control (que j'appelle Label) qui prend pour source un Connector
Pour l'instant, côté Connector j'ai :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
public class Connector : System.ComponentModel.Component
{
private string _lang = "Fr";
private XmlDocument _source;
private string _sourceFileName = null;
/// <summary>
///
/// </summary>
public Connector()
{
this._source = new XmlDocument();
}
/// <summary>
///
/// </summary>
[Bindable(true),
Category("Connection"),
DefaultValue(true)]
public string Lang
{
get
{
return this._lang;
}
set
{
this._lang = value;
}
}
[
DefaultValue(""),
Editor(typeof(System.Web.UI.Design.XmlUrlEditor), typeof(System.Drawing.Design.UITypeEditor)),
]
public string Source
{
get
{
return this._sourceFileName;
}
set
{
this._sourceFileName = value;
}
}
/// <summary>
///
/// </summary>
/// <param name="nameObject"></param>
/// <returns></returns>
internal string GetValue(string nameObject)
{
XmlNode obj = this._source.SelectSingleNode("//object[@id='" + nameObject + "']/text[@lang='" + this._lang + "']");
if(obj != null)
return obj.InnerText;
else
return string.Empty;
}
} |
Et côté Label :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| /// <summary>
/// Description résumée de Label.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:Label runat=server></{0}:Label>")]
public class Label : System.Web.UI.WebControls.Label
{
private Connector _source;
[Bindable(true),
Category("DataSource"),
DefaultValue("")]
public Connector Source
{
get
{
return this._source;
}
set
{
this._source = value;
}
}
/// <summary>
/// Génère ce contrôle dans le paramètre de sortie spécifié.
/// </summary>
/// <param name="output"> Le writer HTML vers lequel écrire </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(this._source.GetValue(this.ID));
}
} |
Côté ASPX, ça me donne cela :
Code:
1 2
| </CC1:CONNECTOR>
<cc1:Label id="Label1" runat="server" Source="connector3"></cc1:Label> |
Donc j'aimerai pouvoir :
- ajouter une boite de dialogue à la propriété Source du Connector,
- que les propriétés du Connector soient visible dans le ASPX (comme pour le Label)... hors là j'ai juste un </CC1:CONNECTOR> (les propriétés se mettent dans le code behind... c'est pénible :p)
- Pouvoir mettre à jour automatiquement tous les éléments connectés à mon Connector (en cas de changement de fichier source par exemple)
Pour tout ça, j'ai besoin d'un gros coup de main ;-)
Si quelqu'un a déjà fait un truc de similaire, ça m'intéresse