There are two ways to create localized versions of a library:
Both methods have their advantages and disadvantages, as described in the following sections.
Localized resource assemblies in a single packageIncluding localized resource assemblies in a single package is typically the simplest approach. To do this, create folders within lib
for supported language other than the package default (assumed to be en-us). In these folders you can place resource assemblies and localized IntelliSense XML files.
For example, the following folder structure supports, German (de), Italian (it), Japanese (ja), Russian (ru), Chinese (Simplified) (zh-Hans), and Chinese (Traditional) (zh-Hant):
lib
âââânet40
â Contoso.Utilities.dll
â Contoso.Utilities.xml
â
ââââde
â Contoso.Utilities.resources.dll
â Contoso.Utilities.xml
â
ââââit
â Contoso.Utilities.resources.dll
â Contoso.Utilities.xml
â
ââââja
â Contoso.Utilities.resources.dll
â Contoso.Utilities.xml
â
ââââru
â Contoso.Utilities.resources.dll
â Contoso.Utilities.xml
â
ââââzh-Hans
â Contoso.Utilities.resources.dll
â Contoso.Utilities.xml
â
ââââzh-Hant
Contoso.Utilities.resources.dll
Contoso.Utilities.xml
You can see that the languages are all listed underneath the net40
target framework folder. If you're supporting multiple frameworks, then you have a folder under lib
for each variant.
With these folders in place, you then reference all the files in your .nuspec
:
<?xml version="1.0"?>
<package>
<metadata>...
</metadata>
<files>
<file src="lib\**" target="lib" />
</files>
</package>
One example package that uses this approach is Microsoft.Data.OData 5.4.0.
Advantages and disadvantages (localized resource assemblies)Bundling all languages in a single package has a few disadvantages:
.nuspec
file, you can provide metadata for only a single language. That is, NuGet does not present support localized metadata.However, it also has a few benefits:
Similar to how .NET Framework supports satellite assemblies, this method separates localized resources and IntelliSense XML files into satellite packages.
Do to this, your primary package uses the naming convention {identifier}.{version}.nupkg
and contains the assembly for the default language (such as en-US). For example, ContosoUtilities.1.0.0.nupkg
would contain the following structure:
lib
âââânet40
ContosoUtilities.dll
ContosoUtilities.xml
A satellite assembly then uses the naming convention {identifier}.{language}.{version}.nupkg
, such as ContosoUtilities.de.1.0.0.nupkg
. The identifier must exactly match that of the primary package.
Because this is a separate package, it has its own .nuspec
file that contains localized metadata. Be mindful that the language in the .nuspec
must match the one used in the filename.
The satellite assembly must also declare an exact version of the primary package as a dependency, using the [] version notation (see Package versioning). For example, ContosoUtilities.de.1.0.0.nupkg
must declare a dependency on ContosoUtilities.1.0.0.nupkg
using the [1.0.0]
notation. The satellite package can, of course, have a different version number than the primary package.
The satellite package's structure must then include the resource assembly and XML IntelliSense file in a subfolder that matches {language}
in the package filename:
lib
âââânet40
ââââde
ContosoUtilities.resources.dll
ContosoUtilities.xml
Note: unless specific subcultures such as ja-JP
are necessary, always use the higher level language identifier, like ja
.
In a satellite assembly, NuGet will recognize only those files in the folder that matches the {language}
in the filename. All others are ignored.
When all of these conventions are met, NuGet will recognize the package as a satellite package and install the localized files into the primary package's lib
folder, as if they had been originally bundled. Uninstalling the satellite package will remove its files from that same folder.
You would create additional satellite assemblies in the same way for each supported language. For an example, examine the set of ASP.NET MVC packages:
{identifier}.{version}.nupkg
{identifier}.{language}.{version}.nupkg
.nuspec
must specify its language to match the filename..nuspec
file. Ranges are not supported.lib\[{framework}\]{language}
folder that exactly matches {language}
in the filename.Using satellite packages has a few benefits:
.nuspec
file and thus its own localized metadata. This can allow some consumers to find packages more easily by searching nuget.org with localized terms.However, satellite packages have their own set of disadvantages:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4