0

ASP.NET Core App과 공통 라이브러리를 공유하는 .NET Core Console App이 있습니다. 세계화를 공용 프로젝트에 추가해야하고 ASP.NET에서 언어로 새로운 .resx 파일을 쉽게 만들 수 있습니다. some.en.resx내 콘솔 앱에서 IStringLocalizer <T>을 {} .en.resx와 어떻게 사용할 수 있습니까?

현재 서비스를 등록 할 수 있지만 StringLocalizer 클래스를 호출하고 있습니다. 현지화 된 문자열을 반환합니다. 파일에서 .en을 제거하여 작동 시키지만 그 다음에는 내 ASP.NET 프로젝트가 중단됩니다.

마치 기본 언어를 어딘가에 등록 할 필요가 있지만 어디에서 일할 수 없는지.

class Program 
{ 
    static void Main(string[] args) 
    { 
     ServiceCollection serviceCollection = new ServiceCollection(); 
     serviceCollection.AddTransient<MyService>(); 
     serviceCollection.AddSingleton<LoggerFactory>(); 

     serviceCollection 
      .AddLogging() 
      .AddLocalization(); 

     ServiceProvider buildServiceProvider = serviceCollection.BuildServiceProvider(); 
     MyService myService = buildServiceProvider.GetService<MyService>(); 
     string greeting = myService.GetGreeting(); 
     Console.WriteLine(greeting); 
     Console.ReadKey(); 
    } 
} 

public class MyService 
{ 
    private readonly IStringLocalizer<MyService> _stringLocalizer; 

    public MyService(IStringLocalizer<MyService> stringLocalizer) 
    { 
     _stringLocalizer = stringLocalizer; 
    } 

    public string GetGreeting() 
    { 
     return _stringLocalizer.GetString("Greeting"); 
    } 
} 

enter image description here

나는이 작업을 수행 할 수있는 방법이 있습니까?

+1

파일 이름에 .en없이 실제로 작동 했습니까? "인사"가 아닌 "Hello"텍스트를 반환합니까? 그렇다면 전체 테스트 프로젝트를 업로드 할 수 있습니까? –

답변

1

ASP.NET의 동작을 반복적으로 찾을 수있는 방법을 찾지 못했습니다. 나는 .en.resx 파일을 가질 수 없다는 사실을 받아 들여야 만했고 문화적으로 "en"ASP.NET은 기본 .resx 파일을 사용합니다.