Difference between revisions of "Silme:Tutorial:Entity"
Zbraniecki (talk | contribs) (New page: == Entity == The basic unit we use in the localization world is an entity. Entity is a simple object made of ID and a value. ID is a somehow unique identifier of the entity, and the value...) |
Zbraniecki (talk | contribs) |
||
Line 2: | Line 2: | ||
The basic unit we use in the localization world is an entity. | The basic unit we use in the localization world is an entity. | ||
− | Entity is a simple object made of ID and a value. ID is a somehow unique identifier of the entity, and the value is an actual string that you want to present to the user. | + | Entity is a simple object made of ID and a value. |
+ | ID is a somehow unique identifier of the entity, and the value is an actual string that you want to present to the user. | ||
In Verbatim creating a new Entity looks like this: | In Verbatim creating a new Entity looks like this: | ||
<code lang="python"> | <code lang="python"> | ||
+ | from mozilla.l10n.object import Entity | ||
+ | |||
+ | entity = Entity('id','value') | ||
+ | </code> | ||
+ | |||
+ | This simple object is the most atomic unit in every localization format, be it DTD, Gettext, XLIFF or L20n. It's an abstract representation of a row in the l10n array in SQL or it represents a single string in HTML file (in this case ID has to be a unique identifier of the string position in the file). | ||
+ | |||
+ | Of course Entity may be much more complex than that. In some cases you can have a meta data for the single entity, or a comment that is tied to the entity. Because of how popular those two cases are among l10n formats, Entity object has predefined dictionary objects for those two: | ||
+ | |||
+ | |||
+ | <code lang="python"> | ||
+ | from mozilla.l10n.object import Entity | ||
+ | |||
entity = Entity('id','value') | entity = Entity('id','value') | ||
+ | entity.comment['pre'] = u'Comment prefixing the entity' | ||
+ | entity.parameter['author'] = 'Ben' | ||
+ | </code> | ||
+ | |||
+ | == EntityList == | ||
+ | |||
+ | EntityList is a simplest possible class used to store the sequence of entities. | ||
+ | |||
+ | <code lang="python"> | ||
+ | from mozilla.l10n.object import Entity, EntityList | ||
+ | |||
+ | entityList = EntityList() | ||
+ | |||
+ | entity1 = Entity('example.id','Test value') | ||
+ | entityList.addEntity(entity1) | ||
+ | |||
+ | entity2 = Entity('example.id2','Test value2') | ||
+ | entityList.addEntity(entity2) | ||
</code> | </code> | ||
+ | |||
+ | |||
+ | == Advanced == | ||
+ | |||
+ | You may decide to extend Entity class or just add your own properties to the Entity object. |
Revision as of 13:37, 19 May 2008
Entity
The basic unit we use in the localization world is an entity. Entity is a simple object made of ID and a value. ID is a somehow unique identifier of the entity, and the value is an actual string that you want to present to the user.
In Verbatim creating a new Entity looks like this:
from mozilla.l10n.object import Entity
entity = Entity('id','value')
This simple object is the most atomic unit in every localization format, be it DTD, Gettext, XLIFF or L20n. It's an abstract representation of a row in the l10n array in SQL or it represents a single string in HTML file (in this case ID has to be a unique identifier of the string position in the file).
Of course Entity may be much more complex than that. In some cases you can have a meta data for the single entity, or a comment that is tied to the entity. Because of how popular those two cases are among l10n formats, Entity object has predefined dictionary objects for those two:
from mozilla.l10n.object import Entity
entity = Entity('id','value')
entity.comment['pre'] = u'Comment prefixing the entity'
entity.parameter['author'] = 'Ben'
EntityList
EntityList is a simplest possible class used to store the sequence of entities.
from mozilla.l10n.object import Entity, EntityList
entityList = EntityList()
entity1 = Entity('example.id','Test value')
entityList.addEntity(entity1)
entity2 = Entity('example.id2','Test value2')
entityList.addEntity(entity2)
Advanced
You may decide to extend Entity class or just add your own properties to the Entity object.