我才刚刚开始对.net core 2.2应用程序进行本地化,我正在寻找一种从sql数据库中获取区域性的方法。 我正在尝试使用代码在Startup的Configure方法中配置请求本地化对象
import android.os.Bundle;
import android.util.Log;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import com.shockwave.pdfium.PdfDocument;
import java.util.List;
public class ReadingActivity extends Activity implements OnPageChangeListener,OnLoadCompleteListener {
private static final String TAG = ReadingActivity.class.getSimpleName();
public static final String PDF_FILE = "my_book.pdf";
PDFView pdfView ;
Integer pageNumber;
String pdfFileName;
Integer currentPageNumber;
Integer savedPage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reading);
SharedPreferences mySharedPreferences = getPreferences(Context.MODE_PRIVATE);
savedPage = mySharedPreferences.getInt("retrievedPage",0);
pageNumber = savedPage;
pdfView = (PDFView)findViewById(R.id.pdfView);
displayFromAsset(PDF_FILE);
}
private void displayFromAsset(String assetFileName) {
pdfFileName = assetFileName;
pdfView.fromAsset(PDF_FILE)
.defaultPage(pageNumber)
.enableSwipe(true)
.swipeHorizontal(false)
.onPageChange(this)
.enableAnnotationRendering(true)
.onLoad(this)
.scrollHandle(new DefaultScrollHandle(this))
.load();
}
@Override
public void onPageChanged(int page, int pageCount) {
pageNumber = page;
setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
}
@Override
public void loadComplete(int nbPages) {
PdfDocument.Meta meta = pdfView.getDocumentMeta();
printBookmarksTree(pdfView.getTableOfContents(), "-");
}
public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
for (PdfDocument.Bookmark b : tree) {
Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));
if (b.hasChildren()) {
printBookmarksTree(b.getChildren(), sep + "-");
}
}
}
@Override
protected void onStop() {
super.onStop();
SharedPreferences mySharedPreferences = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor myEditor = mySharedPreferences.edit();
savedPage = pdfView.getCurrentPage();
myEditor.putInt("retrievedPage",savedPage);
myEditor.apply();
}
}
我在代码中设置了一个断点,并且看到区域性返回了4个项目,但是对SupportedCultures仅添加了一个项目,而ConfigureServices中的相同代码也可以正常工作。 我在配置服务中使用的代码是
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IStringLocalizerFactory localizerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseStatusCodePagesWithReExecute("/Error/{0}");
}
string defaultCulture = null;
var supportedCultures = new List<CultureInfo>();
using (var scope = app.ApplicationServices.CreateScope())
{
var db = scope.ServiceProvider.GetService<IRepository<Language>>();
defaultCulture = db.FindBy(c => c.IsSelected).FirstOrDefault().Code;
var langs = db.GetAll().ToList();
foreach (var item in langs)
{
CultureInfo ci = new CultureInfo(item.Code);
supportedCultures.Add(ci);
}
}
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(defaultCulture),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseSession();
app.UseAuthentication();
app.UseMvc();
}
使用Configure方法中的代码在我的方法上有错误吗?