星期三, 12月 26, 2007

[.Net]How to monorail by Generator tool(4)

在研究過之後,我決定在 ScaffoldHelper.cs 裡面添加 GetText 這個函數,用來取得字串。

#region Localization helpers
public string GetText( IResource resource, string str )
{
if( resource==null )
return str;

object resStr = resource[ str ];
if( resStr==null )
return str;

return resStr.ToString();
}
#endregion

這樣在 .vm (template)檔案裡面,就可以這麼使用,以取得本地化後的字串:

$ScaffoldHelper.GetText($textres, "Name" )

當然你還是可以用原先的方法:

$textres.Name


所以 PageBrowser() 也可以跟著修正為:

#region Pagination helpers
public string PageBrowser( Page page )
{
return PageBrowser( page, null );
}

public string PageBrowser( Page page, IResource resource )
{
StringWriter output = new StringWriter();
PaginationHelper helper = new PaginationHelper();
helper.SetController(this.Controller);
string firstText = GetText( resource, "First" );
string prevText = GetText( resource, "Previous" );
string nextText = GetText( resource, "Next" );
string lastText = GetText( resource, "Last" );

if (page.HasFirst)
output.Write(helper.CreatePageLink(1, firstText ));
else
output.Write( firstText );

output.Write(" | ");

if (page.HasPrevious)
output.Write(helper.CreatePageLink(page.PreviousIndex, prevText ));
else
output.Write(prevText);

output.Write(" | ");

if (page.HasNext)
output.Write(helper.CreatePageLink(page.NextIndex, nextText ));
else
output.Write( nextText );

output.Write(" | ");

if (page.HasLast)
output.Write(helper.CreatePageLink(page.LastIndex, lastText ));
else
output.Write( lastText );

return output.ToString();
}
#endregion


最後在資源檔裡面加上必要的字串並且修改 .vm (template)以後,就可以得到本土化後的結果。

沒有留言:

您或許對這些文章有興趣

Related Posts Plugin for WordPress, Blogger...