2014-06-12 77 views
0

我正在使用Tapestry5開發web應用程序。在我的應用程序中,我想集成多語言概念。我有兩個屬性文件是app_it.properties和app_fr.properties。但沒有價值,只有關鍵。掛毯中的多語言概念5

app_it.properties

aboutus= 
termsandcondns= 
privacy= 

app_fr.properties

aboutus= 
termsandcondns= 
privacy= 

在這裏,我想在運行時設置鍵的值。該密鑰的值基於國家代碼從我的數據庫中獲取。可以設置嗎?

請幫幫我。

回答

1

在掛毯,所有服務通過tapestry IOC

在這種情況下是重寫,你將提供ComponentMessagesSource

定製的,基於數據庫的實現如果你想徹底刪除基於屬性文件的功能,你會override ComponentMessagesSource。如果不是,您可能會使用現有服務,並使用屬性文件和數據庫值的組合。

0

你可以貢獻自己的實現org.apache.tapestry5.ioc.Resource,這可能會阻止需要使用Tapestry的內部API。

@Contribute(ComponentMessagesSource.class) 
public static void provideMessages(OrderedConfiguration<Resource> configuration) { 
    configuration.add("DBMessages", new Resource() { 
     // implement interface methods 
    }); 
} 

你可以,當然,構建從一個單獨的服務,提供與數據庫連接或任何你希望從中獲取您的信息資源內的資源實例。棘手的一點可能是如何實現明確爲文件/目錄結構設計的方法,以及更動態的工作。

/** 
* Returns a Resource based on a relative path, relative to the folder containing the resource. Understands the "." 
* (current folder) and ".." (parent folder) conventions, and treats multiple sequential slashes as a single slash. 
* <p/> 
* Virtual resources (resources fabricated at runtime) return themselves. 
*/ 
Resource forFile(String relativePath); 

/** 
* Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the 
* Resource. 
*/ 
String getFolder(); 

好吧,我想你得有在掛毯源代碼偷看,看看如何對現有資源實現的工作。