Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterlv committed May 28, 2024
1 parent 0723061 commit 8fe8006
Show file tree
Hide file tree
Showing 49 changed files with 1,898 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: .NET Core

on: [push]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v1

- name: Build with dotnet
run: dotnet build --configuration Release

- name: Test
run: dotnet test --configuration Release
40 changes: 40 additions & 0 deletions .github/workflows/nuget-master-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 去掉注释可以合并 master 分支自动打包
# 为什么不期望推送 master 自动打包?原因是打出来的 CBB 没有 Tag 不利于回滚找到代码

# name: publish nuget

# on:
# push:
# branches:
# - master

# jobs:
# build:

# runs-on: windows-latest

# steps:
# - uses: actions/checkout@v1

# - name: Setup .NET Core
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: 3.1.300

# - name: Build with dotnet
# run: |
# dotnet build --configuration Release
# dotnet pack --configuration Release --no-build

# - name: Install Nuget
# uses: nuget/setup-nuget@v1
# with:
# nuget-version: '5.x'

# - name: Add private GitHub registry to NuGet
# run: |
# nuget sources add -name github -Source https://nuget.pkg.github.com/dotnet-campus/index.json -Username dotnet-campus -Password ${{ secrets.GITHUB_TOKEN }}
# - name: Push generated package to GitHub registry
# run: |
# nuget push .\bin\Release\*.nupkg -Source github -SkipDuplicate
# nuget push .\bin\Release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }}
44 changes: 44 additions & 0 deletions .github/workflows/nuget-tag-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: publish nuget

on:
push:
tags:
- '*'

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v1

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.300

- name: Install dotnet tool
run: dotnet tool install -g dotnetCampus.TagToVersion

- name: Set tag to version
run: dotnet TagToVersion -t ${{ github.ref }}

- name: Build with dotnet
run: |
dotnet build --configuration Release
dotnet pack --configuration Release --no-build
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: '5.x'

- name: Add private GitHub registry to NuGet
run: |
nuget sources add -name github -Source https://nuget.pkg.github.com/dotnet-campus/index.json -Username dotnet-campus -Password ${{ secrets.GITHUB_TOKEN }}
- name: Push generated package to GitHub registry
run: |
nuget push .\artifacts\package\release\*.nupkg -Source github -SkipDuplicate
nuget push .\artifacts\package\release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }}
25 changes: 25 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project>

<Import Project="build\Version.props" />

<!-- 框架和语言信息 -->
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
</PropertyGroup>

<!--库信息 -->
<PropertyGroup>
<Description>使用源生成器为你的项目增加本地化源代码,使得你可以利用 IDE 的智能感知来使用多语言。</Description>
<Authors>dotnet-campus</Authors>
<Company>dotnet campus(.NET 职业技术学院)</Company>
<Copyright>Copyright $([System.DateTime]::Now.ToString(`yyyy`)) &#169; dotnet campus, All Rights Reserved.</Copyright>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dotnet-campus/dotnetCampus.SourceLocalizations</RepositoryUrl>
<PackageProjectUrl>https://github.com/dotnet-campus/dotnetCampus.SourceLocalizations</PackageProjectUrl>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# dotnetCampus.SourceLocalizations

| Build | NuGet |
|--|--|
|![](https://github.com/dotnet-campus/dotnetCampus.SourceLocalizations/workflows/.NET%20Core/badge.svg)|[![](https://img.shields.io/nuget/v/dotnetCampus.SourceLocalizations.svg)](https://www.nuget.org/packages/dotnetCampus.SourceLocalizations)|
5 changes: 5 additions & 0 deletions build/Version.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.1.0-alpha01</Version>
</PropertyGroup>
</Project>
57 changes: 57 additions & 0 deletions dotnetCampus.SourceLocalizations.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnetCampus.Localizations", "src\dotnetCampus.Localizations\dotnetCampus.Localizations.csproj", "{9A8FEE27-F589-48E4-BF31-CC0D5CD4A3F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnetCampus.Localizations.Analyzer", "src\dotnetCampus.Localizations.Analyzer\dotnetCampus.Localizations.Analyzer.csproj", "{48BE5845-BF2F-48CD-8214-2418E72A9BFF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E407F54C-8E41-4F4E-B9BF-9864B6178E5F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalizationSample", "samples\LocalizationSample\LocalizationSample.csproj", "{F330175F-FC20-4D42-921A-747AC296D1B9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4239BEE3-D480-4874-83E1-353B35F1BD86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnetCampus.Localizations.Tests", "tests\dotnetCampus.Localizations.Tests\dotnetCampus.Localizations.Tests.csproj", "{3170B151-6A25-4321-BF09-EFC516E32F8D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{6E0F9A76-51AE-49A7-B74C-CA194F6CD37C}"
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
README.md = README.md
Directory.Build.props = Directory.Build.props
build\Version.props = build\Version.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9A8FEE27-F589-48E4-BF31-CC0D5CD4A3F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A8FEE27-F589-48E4-BF31-CC0D5CD4A3F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A8FEE27-F589-48E4-BF31-CC0D5CD4A3F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A8FEE27-F589-48E4-BF31-CC0D5CD4A3F0}.Release|Any CPU.Build.0 = Release|Any CPU
{48BE5845-BF2F-48CD-8214-2418E72A9BFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48BE5845-BF2F-48CD-8214-2418E72A9BFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48BE5845-BF2F-48CD-8214-2418E72A9BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48BE5845-BF2F-48CD-8214-2418E72A9BFF}.Release|Any CPU.Build.0 = Release|Any CPU
{F330175F-FC20-4D42-921A-747AC296D1B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F330175F-FC20-4D42-921A-747AC296D1B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F330175F-FC20-4D42-921A-747AC296D1B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F330175F-FC20-4D42-921A-747AC296D1B9}.Release|Any CPU.Build.0 = Release|Any CPU
{3170B151-6A25-4321-BF09-EFC516E32F8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3170B151-6A25-4321-BF09-EFC516E32F8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3170B151-6A25-4321-BF09-EFC516E32F8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3170B151-6A25-4321-BF09-EFC516E32F8D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F330175F-FC20-4D42-921A-747AC296D1B9} = {E407F54C-8E41-4F4E-B9BF-9864B6178E5F}
{3170B151-6A25-4321-BF09-EFC516E32F8D} = {4239BEE3-D480-4874-83E1-353B35F1BD86}
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions samples/LocalizationSample/LocalizationSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\dotnetCampus.Localizations\dotnetCampus.Localizations.csproj" />
</ItemGroup>

<ItemGroup>
<LocalizationFile Include="Localizations\**\*.yaml" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions samples/LocalizationSample/Localizations/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A.A1: "Words"
A.A2: "Error code: {errorCode:int}"
A.A3: "Error: {error}"
3 changes: 3 additions & 0 deletions samples/LocalizationSample/Localizations/zh-hans.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A.A1: "文本"
A.A2: "错误码:{errorCode:int}"
A.A3: "错误:{error}"
61 changes: 61 additions & 0 deletions samples/LocalizationSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Frozen;
using System.ComponentModel;
using dotnetCampus.Localizations;

namespace LocalizationSample;

internal class Program
{
public static void Main(string[] args)
{
}
}

[LocalizedConfiguration(Default = "zh-hans", Current = "en")]
internal partial class Lang;

[EditorBrowsable(EditorBrowsableState.Never)]
public interface ILocalized_Root : ILocalizedStringProvider
{
ILocalized_Root_A A => (ILocalized_Root_A)this;
}

[EditorBrowsable(EditorBrowsableState.Never)]
public interface ILocalized_Root_A : ILocalizedStringProvider
{
LocalizedString A1 => this.Get0("A.A1");

LocalizedString<int> A2 => this.Get1<int>("A.A2");

LocalizedString<object> A3 => this.Get1<object>("A.A3");
}

public class Lang_ZhHans(ILocalized_Root? fallback) : ILocalized_Root,
ILocalized_Root_A
{
private readonly FrozenDictionary<string, string> _strings = new Dictionary<string, string>
{
{ "A.A1", "文字" },
{ "A.A2", "错误码:{0}" },
{ "A.A3", "错误:{0}" },
}.ToFrozenDictionary();

public string this[string key] => _strings[key] ?? fallback![key];

public string IetfLanguageTag => "zh-hans";
}

public class Lang_En(ILocalized_Root? fallback) : ILocalized_Root,
ILocalized_Root_A
{
private readonly FrozenDictionary<string, string> _strings = new Dictionary<string, string>
{
{ "A.A1", "Words" },
{ "A.A2", "Error code: {0}" },
{ "A.A3", "Error: {0}" },
}.ToFrozenDictionary();

public string this[string key] => _strings[key] ?? fallback![key];

public string IetfLanguageTag => "en";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
global using dotnetCampus.Localizations.Assets.Analyzers;
using dotnetCampus.Localizations.Assets.Templates;

namespace dotnetCampus.Localizations.Assets.Analyzers;

/// <summary>
/// 为生成 <see cref="Localization"/> 的分部类的部分待填充代码提供占位符。
/// </summary>
/// <param name="ietfLanguageTag"></param>
/// <param name="fallback"></param>
public class LspPlaceholder(string ietfLanguageTag, ILocalized_Root? fallback) : ILocalized_Root
{
/// <inheritdoc />
public string IetfLanguageTag => ietfLanguageTag;

/// <inheritdoc />
public string this[string key] => fallback![key];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable enable

using ILocalizedStringProvider = global::dotnetCampus.Localizations.ILocalizedStringProvider;
using LocalizedString = global::dotnetCampus.Localizations.LocalizedString;

namespace dotnetCampus.Localizations.Assets.Templates;

[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public interface ILocalized_Root : ILocalizedStringProvider
{
// <FLAG>
// ILocalized_Root_A A => (ILocalized_Root_A)this;
// LocalizedString A1 => this.Get0("A.A1");
// </FLAG>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#nullable enable

namespace dotnetCampus.Localizations.Assets.Templates;

partial class Localization
{
/// <summary>
/// 获取默认的本地化字符串集。
/// </summary>
public static ILocalized_Root Default { get; } = new LspPlaceholder("default", null);

/// <summary>
/// 获取当前的本地化字符串集。
/// </summary>
public static ILocalized_Root Current { get; private set; } = new LspPlaceholder("current", null);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#nullable enable

using global::System.Collections.Frozen;

namespace dotnetCampus.Localizations.Assets.Templates;

/// <inheritdoc />
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public class LocalizationValues(ILocalized_Root? fallback) : ILocalized_Root
{
/// <inheritdoc />
public string IetfLanguageTag => "default";

/// <inheritdoc />
public string this[string key] => _strings[key] ?? fallback![key];

private readonly FrozenDictionary<string, string> _strings = new Dictionary<string, string>
{
// <FLAG>
{ "A.A1", "文字" },
{ "A.A2", "错误码:{0}" },
{ "A.A3", "错误:{0}" },
// </FLAG>
}.ToFrozenDictionary();
}
Loading

0 comments on commit 8fe8006

Please sign in to comment.