66using System . Linq ;
77
88using ResXManager . Infrastructure ;
9- using TomsToolbox . Essentials ;
109
1110public static class ProjectFileExtensions
1211{
@@ -52,7 +51,7 @@ public static bool IsResourceFile(this ProjectFile projectFile)
5251 return IsResourceFile ( filePath , extension ) ;
5352 }
5453
55- public static CultureKey GetCultureKey ( this ProjectFile projectFile , CultureInfo neutralResourcesLanguage )
54+ public static CultureDefinition GetCultureDefinition ( this ProjectFile projectFile , CultureInfo neutralResourcesLanguage )
5655 {
5756 var extension = projectFile . Extension ;
5857 var filePath = projectFile . FilePath ;
@@ -62,13 +61,21 @@ public static CultureKey GetCultureKey(this ProjectFile projectFile, CultureInfo
6261 var fileNameWithoutExtension = Path . GetFileNameWithoutExtension ( filePath ) ;
6362 var cultureName = Path . GetExtension ( fileNameWithoutExtension ) . TrimStart ( '.' ) ;
6463
65- if ( cultureName . IsNullOrEmpty ( ) )
66- return CultureKey . Neutral ;
67-
6864 if ( ! CultureHelper . IsValidCultureName ( cultureName ) )
69- return CultureKey . Neutral ;
65+ return new ( CultureKey . Neutral , CultureRepresentation . Name ) ;
66+
67+ var cultureKey = new CultureKey ( cultureName ) ;
68+
69+ if ( ! int . TryParse ( cultureName , NumberStyles . Integer , CultureInfo . InvariantCulture , out var lcid ) )
70+ return new ( cultureKey , CultureRepresentation . Name ) ;
71+
72+ if ( Equals ( neutralResourcesLanguage , CultureInfo . GetCultureInfo ( lcid ) ) )
73+ {
74+ return new ( CultureKey . Neutral , CultureRepresentation . Lcid ) ;
75+ }
76+
77+ return new ( cultureKey , CultureRepresentation . Lcid ) ;
7078
71- return new CultureKey ( cultureName ) ;
7279 }
7380
7481 if ( Resw . Equals ( extension , StringComparison . OrdinalIgnoreCase ) )
@@ -80,7 +87,9 @@ public static CultureKey GetCultureKey(this ProjectFile projectFile, CultureInfo
8087
8188 var culture = cultureName . ToCulture ( ) ;
8289
83- return Equals ( neutralResourcesLanguage , culture ) ? CultureKey . Neutral : new CultureKey ( culture ) ;
90+ var cultureKey = Equals ( neutralResourcesLanguage , culture ) ? CultureKey . Neutral : new CultureKey ( culture ) ;
91+
92+ return new ( cultureKey , CultureRepresentation . Name ) ;
8493 }
8594
8695 throw new InvalidOperationException ( "Unsupported file format: " + extension ) ;
@@ -101,14 +110,30 @@ public static string GetBaseName(this ProjectFile projectFile)
101110 return CultureHelper . IsValidCultureName ( languageName ) ? Path . GetFileNameWithoutExtension ( name ) : name ;
102111 }
103112
104- public static string GetLanguageFileName ( this ProjectFile projectFile , CultureInfo culture )
113+ public static string GetLanguageFileName ( this ResourceLanguage neutralLanguage , CultureInfo culture )
105114 {
115+ var projectFile = neutralLanguage . ProjectFile ;
116+
106117 var extension = projectFile . Extension ;
107118 var filePath = projectFile . FilePath ;
108119
109120 if ( Resx . Equals ( extension , StringComparison . OrdinalIgnoreCase ) )
110121 {
111- return Path . ChangeExtension ( filePath , culture . ToString ( ) ) + @".resx" ;
122+ var baseName = Path . ChangeExtension ( filePath , null ) ;
123+ string cultureTag ;
124+
125+ if ( neutralLanguage . CultureRepresentation == CultureRepresentation . Lcid )
126+ {
127+ // Neutral LCID based resource also includes a language tag in the file, e.g. "Strings.1033.resx" - else we would not have classified it as LCID based.
128+ baseName = Path . ChangeExtension ( baseName , null ) ;
129+ cultureTag = culture . LCID . ToString ( "D" , CultureInfo . InvariantCulture ) ;
130+ }
131+ else
132+ {
133+ cultureTag = culture . Name ;
134+ }
135+
136+ return $ "{ baseName } .{ cultureTag } .resx";
112137 }
113138
114139 if ( Resw . Equals ( extension , StringComparison . OrdinalIgnoreCase ) )
@@ -134,4 +159,4 @@ public static bool IsCSharpFile(this ProjectFile projectFile)
134159 {
135160 return Path . GetExtension ( projectFile . FilePath ) . Equals ( ".cs" , StringComparison . OrdinalIgnoreCase ) ;
136161 }
137- }
162+ }
0 commit comments