我正在使用ngx-translate模块制作一个angular2应用
该服务使用.json文档来查找翻译
首先...我注意到本地json文档的路由是“ / src / assets / i18n /”,就像下一张图片一样:
因此,翻译服务使用默认语言翻译不同文本
这是我的app.component.ts的工作方式:
Failed to process message Load
mono.android.DesignerException: System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> System.DllNotFoundException: e_sqlite3
at mono.android.DesignerException.fromThrowable(DesignerException.java:54)
at mono.android.DesignerSession.checkRenderResultForError(DesignerSession.java:235)
at mono.android.DesignerSession.load(DesignerSession.java:314)
at mono.android.DesignerSession.processMessage(DesignerSession.java:675)
at mono.android.MessageListener.executeMessage(MessageListener.java:88)
at mono.android.MessageListener$Runner.run(MessageListener.java:44)
at java.lang.Thread.run(Thread.java:748)
Caused by: android.runtime.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> System.DllNotFoundException: e_sqlite3
at (wrapper managed-to-native) SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods.sqlite3_libversion_number()
at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number () [0x00000] in <18970a0afc7f4ff79ddf6a2303a8754b>:0
at SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) [0x00008] in <6c81c50555334bedbd88534becf30d81>:0
at SQLitePCL.Batteries_V2.Init () [0x00005] in <089e75ea5306497b83b6e1606896c7dd>:0
at SQLite.SQLiteConnection..cctor () [0x00010] in <eaa146ee868043e287f5507c8701ad9e>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at Artsfiske1.MainPage.OnAppearing () [0x00008] in C:\Users\Magnus\source\repos\Artsfiske1\Artsfiske1\Artsfiske1\MainPage.xaml.cs:21
at Xamarin.Forms.Page.SendAppearing () [0x00024] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:311
at Xamarin.Forms.Platform.Android.PageRenderer.OnAttachedToWindow () [0x00027] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\PageRenderer.cs:42
at Android.Views.View.n_OnAttachedToWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <a10f61e70eeb434e952fef884856c199>:0
at (wrapper dynamic-method) System.Object.11(intptr,intptr)
at md51558244f76c53b6aeda52c8a337f2c37.PageRenderer.n_onAttachedToWindow(Native Method)
at md51558244f76c53b6aeda52c8a337f2c37.PageRenderer.onAttachedToWindow(PageRenderer.java:55)
at android.view.View.dispatchAttachedToWindow(View.java:17445)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3326)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3333)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3333)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3333)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:334)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:270)
at mono.android.DesignerSession.load(DesignerSession.java:307)
... 4 more
因此该服务使用“ en.json”,“ es.json”和“ fr.json”来匹配翻译。
所以我的问题是
如何避免使用“ json”文档并使文本与数据库中的文本匹配?
因此不必重新构建客户端即可获得新的翻译更新,只需将其添加到数据库并无需重新构建即可自动翻译
答案 0 :(得分:3)
Ngx-translate有一个setTranslation方法,该方法接受Lang键和JSON对象-您可以从任何地方(例如数据库)加载JSON对象,并使用此对象进行设置
setTranslation(lang: string, translations: Object, shouldMerge: boolean = false): Manually sets an object of translations for a given language, set shouldMerge to true if you want to append the translations instead of replacing them
文档:https://github.com/ngx-translate/core/blob/master/README.md#api