Bug 1035: More work on i18n, this time mostly in adl2controllerclasses

This commit is contained in:
sb 2008-05-27 16:27:27 +00:00
parent abbdd73ddf
commit 30260bd69e
3 changed files with 83 additions and 57 deletions

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes Transform ADL into (partial) controller classes
$Author: sb $ $Author: sb $
$Revision: 1.30 $ $Revision: 1.31 $
$Date: 2008-05-21 13:00:56 $ $Date: 2008-05-27 16:27:27 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -32,7 +32,13 @@
client's locale --> client's locale -->
<xsl:param name="locale" select="en-UK"/> <xsl:param name="locale" select="en-UK"/>
<!-- The C# namespace within which I shall generate controllers --> <!-- bug 1896 : boilerplate text in views should be tailored to the locale of
the expected user. Unfortunately I haven't yet worked out how to do
conditional includes in XSLT, so this is a step on the way to a solution,
not a solution in itself. -->
<xsl:include href="i18n-en-GB-include.xslt"/>
<!-- The C# namespace within which I shall generate controllers -->
<xsl:param name="controllerns" select="Unset"/> <xsl:param name="controllerns" select="Unset"/>
<!-- The C# namespace used by the entities for this project --> <!-- The C# namespace used by the entities for this project -->
<xsl:param name="entityns" select="Unset"/> <xsl:param name="entityns" select="Unset"/>
@ -66,7 +72,7 @@
// //
// Automatically generated abstract super class for controllers for the // Automatically generated abstract super class for controllers for the
// <xsl:value-of select="/adl:application/@name"/> application; generated using // <xsl:value-of select="/adl:application/@name"/> application; generated using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.30 $', 10)"/> // adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.31 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
@ -129,7 +135,7 @@ namespace <xsl:value-of select="$controllerns"/> {
// //
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s // Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using // Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.30 $', 10)"/> // adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.31 $', 10)"/>
// //
// This file is automatically generated; DO NOT EDIT IT. // This file is automatically generated; DO NOT EDIT IT.
// //
@ -454,16 +460,18 @@ namespace <xsl:value-of select="$controllerns"/> {
hibernator.Flush(); hibernator.Flush();
tx.Commit(); tx.Commit();
messages.Add( "Record saved successfully"); messages.Add( "<xsl:call-template name="i18n-record-saved"/>");
} /* try actually commit */ } /* try actually commit */
catch ( Exception any) { catch ( Exception any) {
tx.Rollback(); tx.Rollback();
messages.Add( "Record not saved"); messages.Add( "<xsl:call-template name="i18n-record-not-saved"/>");
throw any; throw any;
} }
} /* if ( record != null) */ } /* if ( record != null) */
else { else {
throw new ApplicationException( String.Format( "No record of type <xsl:value-of select="@name"/> with the key values supplied was found")); throw new ApplicationException( String.Format( "<xsl:call-template name="i18n-record-not-found">
<xsl:with-param name="entity-name" select="@name"/>
</xsl:call-template>"));
} }
} /* if ( HasNoErrors()) */ } /* if ( HasNoErrors()) */
} /* try */ } /* try */
@ -697,7 +705,9 @@ namespace <xsl:value-of select="$controllerns"/> {
<xsl:apply-templates select="adl:ifmissing[@locale=$locale]"/> <xsl:apply-templates select="adl:ifmissing[@locale=$locale]"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
"You must supply a value for <xsl:value-of select="@name"/>" "<xsl:call-template name="i18n-value-required">
<xsl:with-param name="property-name" select="@name"/>
</xsl:call-template>"
</xsl:otherwise> </xsl:otherwise>
</xsl:choose>); </xsl:choose>);
} }
@ -714,16 +724,6 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:template> </xsl:template>
<xsl:template match="adl:form"> <xsl:template match="adl:form">
<!-- xsl:variable name="key">
<xsl:call-template name="primary-key-name">
<xsl:with-param name="entity" select="ancestor::adl:entity"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="keytype">
<xsl:call-template name="primary-key-csharp-type">
<xsl:with-param name="entity" select="ancestor::adl:entity"/>
</xsl:call-template>
</xsl:variable -->
/// &lt;summary&gt; /// &lt;summary&gt;
/// Handle the submission of the form named <xsl:value-of select="@name"/> /// Handle the submission of the form named <xsl:value-of select="@name"/>
/// &lt;/summary&gt; /// &lt;/summary&gt;
@ -732,7 +732,7 @@ namespace <xsl:value-of select="$controllerns"/> {
string command = Form[ "command"]; string command = Form[ "command"];
if ( command == null) { if ( command == null) {
throw new Exception( "No command?"); throw new Exception( "<xsl:call-template name="i18n-command-not-found"/>");
} }
else else
<xsl:for-each select=".//verb"> <xsl:for-each select=".//verb">
@ -766,7 +766,9 @@ namespace <xsl:value-of select="$controllerns"/> {
} }
else else
{ {
throw new Exception( String.Format("Unrecognised command '{0}'", command)); throw new Exception( String.Format("<xsl:call-template name="i18n-command-not-found">
<xsl:with-param name="command" select="'{0}'"/>
</xsl:call-template>", command));
} }
} }

View file

@ -13,8 +13,8 @@
Transform ADL into velocity view templates Transform ADL into velocity view templates
$Author: sb $ $Author: sb $
$Revision: 1.22 $ $Revision: 1.23 $
$Date: 2008-05-26 14:40:08 $ $Date: 2008-05-27 16:27:27 $
--> -->
<!-- WARNING WARNING WARNING: Do NOT reformat this file! <!-- WARNING WARNING WARNING: Do NOT reformat this file!
Whitespace (or lack of it) is significant! --> Whitespace (or lack of it) is significant! -->
@ -124,7 +124,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>, Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.22 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="maybe-delete"> <xsl:call-template name="maybe-delete">
<xsl:with-param name="entity" select="."/> <xsl:with-param name="entity" select="."/>
@ -162,7 +162,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>, Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.22 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="install-scripts"/> <xsl:call-template name="install-scripts"/>
</head> </head>
@ -232,12 +232,6 @@
<!-- layout of forms --> <!-- layout of forms -->
<xsl:template match="adl:form" mode="non-empty-layout"> <xsl:template match="adl:form" mode="non-empty-layout">
<xsl:variable name="formname" select="@name"/> <xsl:variable name="formname" select="@name"/>
<xsl:variable name="aoran">
<xsl:call-template name="i18n-indefinite-article">
<xsl:with-param name="noun" select="ancestor::adl:entity/@name"/>
</xsl:call-template>
<xsl:variable name="initial" select="substring( ancestor::adl:entity/@name, 1, 1)"/>
</xsl:variable>
<xsl:text> <xsl:text>
</xsl:text> </xsl:text>
<xsl:comment>[ cut here: next file '<xsl:value-of select="concat( ancestor::adl:entity/@name, '/', @name)"/>.auto.vm' ]</xsl:comment> <xsl:comment>[ cut here: next file '<xsl:value-of select="concat( ancestor::adl:entity/@name, '/', @name)"/>.auto.vm' ]</xsl:comment>
@ -249,7 +243,7 @@
Auto generated Velocity <xsl:value-of select="@name"/> form for <xsl:value-of select="ancestor::adl:entity/@name"/>, Auto generated Velocity <xsl:value-of select="@name"/> form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.22 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
</xsl:comment> </xsl:comment>
#capturefor( title) #capturefor( title)
#if ( $instance) #if ( $instance)
@ -345,17 +339,11 @@
<xsl:template match="adl:form" mode="empty-layout"> <xsl:template match="adl:form" mode="empty-layout">
<xsl:variable name="formname" select="@name"/> <xsl:variable name="formname" select="@name"/>
<xsl:variable name="aoran">
<xsl:call-template name="i18n-indefinite-article">
<xsl:with-param name="noun" select="ancestor::adl:entity/@name"/>
</xsl:call-template>
<xsl:variable name="initial" select="substring( ancestor::adl:entity/@name, 1, 1)"/>
</xsl:variable>
<xsl:text> <xsl:text>
</xsl:text> </xsl:text>
<xsl:comment>[ cut here: next file '<xsl:value-of select="concat( ancestor::adl:entity/@name, '/', @name)"/>.auto.vm' ]</xsl:comment> <xsl:comment>[ cut here: next file '<xsl:value-of select="concat( ancestor::adl:entity/@name, '/', @name)"/>.auto.vm' ]</xsl:comment>
<xsl:text> <xsl:text>
</xsl:text> </xsl:text>
<html> <html>
<xsl:comment> <xsl:comment>
#if ( $instance) #if ( $instance)
@ -375,7 +363,7 @@
Auto generated Velocity form for <xsl:value-of select="ancestor::adl:entity/@name"/>, Auto generated Velocity form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.22 $', 10)"/> Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="install-scripts"/> <xsl:call-template name="install-scripts"/>
<script type='text/javascript' language='JavaScript1.2'> <script type='text/javascript' language='JavaScript1.2'>
@ -999,7 +987,7 @@
Auto generated Velocity list for <xsl:value-of select="@name"/>, Auto generated Velocity list for <xsl:value-of select="@name"/>,
generated from ADL. generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.22 $', 10)"/> Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
</xsl:comment> </xsl:comment>
#capturefor( title) #capturefor( title)
@ -1038,7 +1026,7 @@
Auto generated Velocity list for <xsl:value-of select="ancestor::adl:entity/@name"/>, Auto generated Velocity list for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL. generated from ADL.
Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.22 $', 10)"/> Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
</xsl:comment> </xsl:comment>
<xsl:call-template name="install-scripts"/> <xsl:call-template name="install-scripts"/>
</head> </head>

View file

@ -22,8 +22,8 @@
Templates are listed in alphabetical order. Templates are listed in alphabetical order.
$Author: sb $ $Author: sb $
$Revision: 1.1 $ $Revision: 1.2 $
$Date: 2008-05-26 14:40:08 $ $Date: 2008-05-27 16:27:32 $
--> -->
<xsl:output method="xml" indent="yes"/> <xsl:output method="xml" indent="yes"/>
@ -40,21 +40,45 @@
<xsl:value-of select="concat( 'Does not meet the format requirements for', $format-name)"/> <xsl:value-of select="concat( 'Does not meet the format requirements for', $format-name)"/>
</xsl:template> </xsl:template>
<xsl:template name="i18n-command-not-found">
<xsl:param name="command"/>
<xsl:choose>
<xsl:when test="$command">
<xsl:value-of select="concat( 'Unrecognised command ', $command)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'No command?'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="i18n-delete-prompt"> <xsl:template name="i18n-delete-prompt">
<xsl:value-of select="'To delete this record'"/> <xsl:value-of select="'To delete this record'"/>
</xsl:template> </xsl:template>
<xsl:template name="i18n-indefinite-article"> <xsl:template name="i18n-indefinite-article">
<!-- a string, presumed to be a noun- e.g. the name of an entity --> <!-- a string, presumed to be a noun - e.g. the name of a domain entity -->
<xsl:param name="noun"/> <xsl:param name="noun"/>
<xsl:variable name="initial" select="substring( $noun, 1, 1)"/> <xsl:variable name="initial" select="substring( $noun, 1, 1)"/>
<xsl:choose> <xsl:choose>
<xsl:when test="$initial = 'A' or $initial = 'a'">an</xsl:when> <xsl:when test="$initial = 'A' or $initial = 'a'">
<xsl:when test="$initial = 'E' or $initial = 'e'">an</xsl:when> <xsl:value-of select="concat( 'an ', $noun)"/>
<xsl:when test="$initial = 'I' or $initial = 'i'">an</xsl:when> </xsl:when>
<xsl:when test="$initial = 'O' or $initial = 'o'">an</xsl:when> <xsl:when test="$initial = 'E' or $initial = 'e'">
<xsl:when test="$initial = 'U' or $initial = 'u'">an</xsl:when> <xsl:value-of select="concat( 'an ', $noun)"/>
<xsl:otherwise>a</xsl:otherwise> </xsl:when>
<xsl:when test="$initial = 'I' or $initial = 'i'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:when test="$initial = 'O' or $initial = 'o'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:when test="$initial = 'U' or $initial = 'u'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat( 'a ', $noun)"/>
</xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:template> </xsl:template>
@ -69,10 +93,10 @@
<xsl:value-of select="concat( 'List', $plural)"/> <xsl:value-of select="concat( 'List', $plural)"/>
</xsl:template> </xsl:template>
<!-- English-laguage syntactic sugar of entity name -->
<xsl:template name="i18n-plural"> <xsl:template name="i18n-plural">
<!-- a string, presumed to be a noun --> <!-- a string, presumed to be a noun -->
<xsl:param name="noun"/> <xsl:param name="noun"/>
<!-- English-laguage syntactic sugar of entity name -->
<xsl:choose> <xsl:choose>
<xsl:when test="$noun='Person'">People</xsl:when> <xsl:when test="$noun='Person'">People</xsl:when>
<!-- add other special cases here --> <!-- add other special cases here -->
@ -80,13 +104,12 @@
<xsl:value-of select="concat( $noun, 'es')"/> <xsl:value-of select="concat( $noun, 'es')"/>
</xsl:when> </xsl:when>
<xsl:when test="starts-with( substring($noun, string-length($noun) ), 'y')"> <xsl:when test="starts-with( substring($noun, string-length($noun) ), 'y')">
<xsl:value-of select="concat( substring( $noun, 0, string-length($noun)), 'ies')"/> <xsl:value-of select="concat( substring( $noun, string-length($noun)), 'ies')"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="concat( $noun, 's')"/> <xsl:value-of select="concat( $noun, 's')"/>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:template> </xsl:template>
<!-- the 'really delete' message, used in two-phase delete process --> <!-- the 'really delete' message, used in two-phase delete process -->
@ -102,6 +125,19 @@
<xsl:value-of select="'Yes, do delete it'"/> <xsl:value-of select="'Yes, do delete it'"/>
</xsl:template> </xsl:template>
<xsl:template name="i18n-record-not-found">
<xsl:param name="entity-name"/>
<xsl:value-of select="concat( 'No record of type ', $entity-name, ' with the key values supplied was found')"/>
</xsl:template>
<xsl:template name="i18n-record-not-saved">
<xsl:value-of select="'Record not saved'"/>
</xsl:template>
<xsl:template name="i18n-record-saved">
<xsl:value-of select="'Record saved successfully'"/>
</xsl:template>
<xsl:template name="i18n-save-prompt"> <xsl:template name="i18n-save-prompt">
<xsl:value-of select="'To save this record'"/> <xsl:value-of select="'To save this record'"/>
</xsl:template> </xsl:template>
@ -117,7 +153,7 @@
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:value-of select="concat( 'The value for ', $property-name, ' must be ', $aoran, ' ', $definition-name)"/> <xsl:value-of select="concat( 'The value for ', $property-name, ' must be ', $aoran)"/>
</xsl:template> </xsl:template>
<xsl:template name="i18n-value-entity"> <xsl:template name="i18n-value-entity">
@ -131,7 +167,7 @@
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:value-of select="concat( 'The value for ', $property-name, ' must be ', $aoran, ' ', $entity-name)"/> <xsl:value-of select="concat( 'The value for ', $property-name, ' must be ', $aoran)"/>
</xsl:template> </xsl:template>
<xsl:template name="i18n-value-required"> <xsl:template name="i18n-value-required">
@ -151,6 +187,6 @@
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:value-of select="concat( 'The value for ', $property-name, ' must be ', $aoran, ' ', $type-name)"/> <xsl:value-of select="concat( 'The value for ', $property-name, ' must be ', $aoran)"/>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>