Skip to content

Commit 818a11e

Browse files
committed
Add LocalizedResources sample
1 parent c8b1ab9 commit 818a11e

File tree

11 files changed

+667
-0
lines changed

11 files changed

+667
-0
lines changed

LocalizedResources/Class1.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Globalization;
2+
3+
namespace LocalizedResources
4+
{
5+
public class Class1
6+
{
7+
public static string locHello()
8+
{
9+
return "Hello from LocalizedResources";
10+
}
11+
12+
public static string locGetString1(string cultureName)
13+
{
14+
return Resource1.ResourceManager.GetString("String1", CultureInfo.GetCultureInfo(cultureName));
15+
}
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<DnaLibrary Name="LocalizedResources Add-In" RuntimeVersion="v4.0">
2+
<ExternalLibrary Path="LocalizedResources.dll" LoadFromBytes="true" Pack="true" />
3+
<Reference Path="fr-FR\LocalizedResources.resources" Pack="true" />
4+
<Reference Path="es\LocalizedResources.resources" Pack="true" />
5+
</DnaLibrary>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{71A8C5B2-759C-4462-8D97-1414A1714204}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>LocalizedResources</RootNamespace>
11+
<AssemblyName>LocalizedResources</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="ExcelDna.Integration, Version=0.33.5730.40390, Culture=neutral, processorArchitecture=MSIL">
34+
<HintPath>packages\ExcelDna.Integration.0.33.9\lib\ExcelDna.Integration.dll</HintPath>
35+
<Private>False</Private>
36+
</Reference>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Class1.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
<Compile Include="Resource1.Designer.cs">
49+
<AutoGen>True</AutoGen>
50+
<DesignTime>True</DesignTime>
51+
<DependentUpon>Resource1.resx</DependentUpon>
52+
</Compile>
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Content Include="LocalizedResources-AddIn.dna">
56+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
57+
</Content>
58+
<None Include="packages.config" />
59+
<None Include="Readme.md" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<EmbeddedResource Include="Resource1.es.resx" />
63+
<EmbeddedResource Include="Resource1.fr-FR.resx" />
64+
<EmbeddedResource Include="Resource1.resx">
65+
<Generator>ResXFileCodeGenerator</Generator>
66+
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
67+
</EmbeddedResource>
68+
</ItemGroup>
69+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
70+
<PropertyGroup>
71+
<PostBuildEvent>xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9.65\tools\ExcelDna.xll" "$(TargetDir)LocalizedResources-AddIn.xll*" /C /Y
72+
xcopy "$(TargetDir)LocalizedResources-AddIn.dna*" "$(TargetDir)LocalizedResources-AddIn64.dna*" /C /Y
73+
xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9.65\tools\ExcelDna64.xll" "$(TargetDir)LocalizedResources-AddIn64.xll*" /C /Y
74+
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9.65\tools\ExcelDnaPack.exe" "$(TargetDir)LocalizedResources-AddIn.dna" /Y
75+
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9.65\tools\ExcelDnaPack.exe" "$(TargetDir)LocalizedResources-AddIn64.dna" /Y</PostBuildEvent>
76+
</PropertyGroup>
77+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
78+
Other similar extension points exist, see Microsoft.Common.targets.
79+
<Target Name="BeforeBuild">
80+
</Target>
81+
<Target Name="AfterBuild">
82+
</Target>
83+
-->
84+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalizedResources", "LocalizedResources.csproj", "{71A8C5B2-759C-4462-8D97-1414A1714204}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{71A8C5B2-759C-4462-8D97-1414A1714204}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{71A8C5B2-759C-4462-8D97-1414A1714204}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{71A8C5B2-759C-4462-8D97-1414A1714204}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{71A8C5B2-759C-4462-8D97-1414A1714204}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("LocalizedResources")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("LocalizedResources")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("71a8c5b2-759c-4462-8d97-1414a1714204")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

LocalizedResources/Readme.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Localized Resources
2+
3+
This project shows how to create and access localized resources from inside an Excel-DNA add-in.
4+
5+
The project was created with the following steps:
6+
* Create new Class Library
7+
8+
Install ExcelDna.AddIn package:
9+
PM> Install-Package ExcelDna.AddIn
10+
11+
Add a test function:
12+
public class Class1
13+
{
14+
public static string locHello()
15+
{
16+
return "Hello from LocalizedResources";
17+
}
18+
}
19+
20+
Add the resources:
21+
* Add new "Resources File"
22+
* In Resource1.rex, edit the String1 resource\
23+
* Copy and paste the Resource1.resx file, and rename the new copy to "Resource1.fr-FR.resx".
24+
* Edit the French String1 to be "Première chaîne".
25+
26+
* Copy and paste, rename to "Resource1.es.resx"
27+
* Edit the Spanish String1 to be "Primera cadena"
28+
29+
30+
Add an accessor function:
31+
public class Class1
32+
{
33+
//...
34+
35+
public static string locGetString1(string cultureName)
36+
{
37+
return Resource1.ResourceManager.GetString("String1", CultureInfo.GetCultureInfo(cultureName));
38+
}
39+
}
40+
41+
Add packing directives to the .dna file to include the localized resources:
42+
<DnaLibrary Name="LocalizedResources Add-In" RuntimeVersion="v4.0">
43+
<ExternalLibrary Path="LocalizedResources.dll" LoadFromBytes="true" Pack="true" />
44+
<Reference Path="fr-FR\LocalizedResources.resources" Pack="true" />
45+
<Reference Path="es\LocalizedResources.resources" Pack="true" />
46+
</DnaLibrary>
47+
48+
Test and run:
49+
* Press F5 to build and load in Excel
50+
* =locHello()
51+
* =locGetString1()
52+
* =locGetString1("en")
53+
* =locGetString1("fr-FR")
54+
* =locGetString1("es-AR") (Note fallback to "es" resources)
55+
56+
TODO:
57+
* Implement and test packing for resources - expected for Excel-DNA v. 0.34.

LocalizedResources/Resource1.Designer.cs

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)