Skip to content

Commit

Permalink
MAINTENANCE: refactoring, several breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jslachta committed Oct 17, 2022
1 parent 28fb4a9 commit 46107bb
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 196 deletions.
68 changes: 29 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
name: Build

name: Sonar-Build
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: windows-latest
sonarcloud:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v1
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"jslachta_LocaleNames" /o:"jslachta" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build src/LocaleNames.sln
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0

- name: sonarscan-dotnet
uses: highbyte/sonarscan-dotnet@v2.1.3
with:
# The key of the SonarQube project
sonarProjectKey: jslachta_LocaleNames
# The name of the SonarQube project
sonarProjectName: LocaleNames
# The name of the SonarQube organization in SonarCloud. For hosted SonarQube, skip this setting.
sonarOrganization: jslachta
# Optional command arguments to 'dotnet build'
dotnetBuildArguments: ./src
# Optional command arguments to 'dotnet test'
dotnetTestArguments: ./src --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
# Optional extra command arguments the the SonarScanner 'begin' command
sonarBeginArguments: /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" -d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx"
# The SonarQube server URL. For SonarCloud, skip this setting.
sonarHostname: https://sonarcloud.io
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ The translation data are generated from [CLDR locale data for internationalizati
### Find all language codes

```
var allLanguageCodes = LocaleNames.ForLanguageCode("en-US").AllLanguageCodes;
var allLanguageCodes = LocaleNamesFactory.ForLanguageCode("en-US").AllLanguageCodes;
```

### Find language name

```
var translatedLanguageName = LocaleNames.ForCultureInfo(new CultureInfo("en-US")).FindLanguageName("cs-CZ");
var translatedLanguageName = LocaleNamesFactory.ForCultureInfo(new CultureInfo("en-US")).FindLanguageName("cs-CZ");
```

### Find language code

```
var languageCode = LocaleNames.ForCultureInfo(new CultureInfo("en-US")).FindLanguageCode("Czech");
var languageCode = LocaleNamesFactory.ForCultureInfo(new CultureInfo("en-US")).FindLanguageCode("Czech");
```

### Find all country codes

```
var allCountryCodes = LocaleNames.ForLanguageCode("en-US").AllCountryCodes;
var allCountryCodes = LocaleNamesFactory.ForLanguageCode("en-US").AllCountryCodes;
```

### Find country name

```
var translatedCountryName = LocaleNames.ForCultureInfo(new CultureInfo("en-US")).FindCountryName("DE");
var translatedCountryName = LocaleNamesFactory.ForCultureInfo(new CultureInfo("en-US")).FindCountryName("DE");
```

### Find country code

```
var countryCode = LocaleNames.ForCultureInfo(new CultureInfo("en-US")).FindCountryCode("Germany");
var countryCode = LocaleNamesFactory.ForCultureInfo(new CultureInfo("en-US")).FindCountryCode("Germany");
```
# Stats
![Alt](https://repobeats.axiom.co/api/embed/864145fa59a424553c94a73d2343776612860b15.svg "Repobeats analytics image")

# Contributing

Contributions are welcome. Feel free to file issues and pull requests on the repo.
Contributions are welcome. Feel free to file issues and pull requests on the repo.
8 changes: 4 additions & 4 deletions src/LocaleNames.Test/FactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FactoryTests
[TestMethod]
public void LocaleNames_Factory_ForLanguageCode_On_Windows_Should_Have_Invariant_Culture()
{
var localeNames = LocaleNames.ForLanguageCode("unknown code");
var localeNames = LocaleNamesFactory.ForLanguageCode("unknown code");

if (OperatingSystem.IsWindows())
{
Expand All @@ -29,7 +29,7 @@ public void LocaleNames_Factory_ForLanguageCode_On_Windows_Should_Have_Invariant
[TestMethod]
public void LocaleNames_Factory_ForCultureInfo_Existing_Culture_Test()
{
var translations = LocaleNames.ForCultureInfo(new System.Globalization.CultureInfo("en-US"));
var translations = LocaleNamesFactory.ForCultureInfo(new System.Globalization.CultureInfo("en-US"));

Assert.AreEqual(new System.Globalization.CultureInfo("en-US"), translations.CultureInfo);
Assert.IsFalse(translations.AreCountryNameTranslationsEmpty);
Expand All @@ -45,7 +45,7 @@ public void LocaleNames_Factory_ForLanguageCode_Test()
/*
* if a valid language code is given, the cultureinfo name should match.
*/
var translations = LocaleNames.ForLanguageCode("cs-CZ");
var translations = LocaleNamesFactory.ForLanguageCode("cs-CZ");

Assert.AreEqual(new System.Globalization.CultureInfo("cs-CZ"), translations.CultureInfo);
Assert.IsFalse(translations.AreCountryNameTranslationsEmpty);
Expand All @@ -61,7 +61,7 @@ public void LocaleNames_Factory_ForLanguageCode_InvalidLanguageCode_Test()
/*
* if a not valid language code is given, the LocaleTranslations will not have any translations.
*/
var translations = LocaleNames.ForLanguageCode("non-existing-code");
var translations = LocaleNamesFactory.ForLanguageCode("non-existing-code");

Assert.IsTrue(translations.AreCountryNameTranslationsEmpty);
Assert.IsTrue(translations.AreLanguageTranslationsEmpty);
Expand Down
4 changes: 2 additions & 2 deletions src/LocaleNames.Test/FindCountryCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FindCountryCodeTests
[TestMethod]
public void LocaleNames_All_Country_Codes_Should_Not_Provide_Variants_And_Continents()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

var countryCodes = localeNames.AllCountryCodes;

Expand All @@ -34,7 +34,7 @@ public void LocaleNames_All_Country_Codes_Should_Not_Provide_Variants_And_Contin
[TestMethod]
public void LocaleNames_Find_country_code_by_name()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

Assert.AreEqual("DE", localeNames.FindCountryCode("Germany"));

Expand Down
4 changes: 2 additions & 2 deletions src/LocaleNames.Test/FindCountryNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FindCountryNameTests
[TestMethod]
public void Find_country_name_by_code()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

Assert.AreEqual("Germany", localeNames.FindCountryName("DE"));
Assert.AreEqual("Czechia", localeNames.FindCountryName("CZ"));
Expand All @@ -22,7 +22,7 @@ public void Find_country_name_by_code()
[TestMethod]
public void Find_all_variants_of_country_name_by_code()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");
var result = localeNames.FindCountryNames("CZ");

Assert.IsTrue(result.Count == 2, "CZ country name has only two variants");
Expand Down
4 changes: 2 additions & 2 deletions src/LocaleNames.Test/FindLanguageCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FindLanguageCodeTests
[TestMethod]
public void LocaleNames_All_Language_Codes_Should_Not_Provide_Variants()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

var languageCodes = localeNames.AllLanguageCodes;

Expand All @@ -31,7 +31,7 @@ public void LocaleNames_All_Language_Codes_Should_Not_Provide_Variants()
[TestMethod]
public void LocaleNames_Find_language_code_by_name()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

Assert.AreEqual("de", localeNames.FindLanguageCode("German"));

Expand Down
10 changes: 5 additions & 5 deletions src/LocaleNames.Test/FindLanguageNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FindLanguageNameTests
[TestMethod]
public void LocaleNames_Find_language_name_for_given_culture()
{
var localeNames = LocaleNames.ForCultureInfo(new CultureInfo("cs-CZ"));
var localeNames = LocaleNamesFactory.ForCultureInfo(new CultureInfo("cs-CZ"));

Assert.AreEqual("čeština", localeNames.FindLanguageName("cs"));

Expand All @@ -25,7 +25,7 @@ public void LocaleNames_Find_language_name_for_given_culture()

Assert.AreEqual(null, localeNames.FindLanguageName("unknown code"));

localeNames = LocaleNames.ForCultureInfo(new CultureInfo("yue"));
localeNames = LocaleNamesFactory.ForCultureInfo(new CultureInfo("yue"));

Assert.AreEqual("德文", localeNames.FindLanguageName("de"));

Expand All @@ -37,7 +37,7 @@ public void LocaleNames_Find_language_name_for_given_culture()
[TestMethod]
public void LocaleNames_Find_language_name_for_current_culture()
{
var localeNames = LocaleNames.ForCurrentCulture();
var localeNames = LocaleNamesFactory.ForCurrentCulture();

Assert.AreEqual("angličtina (USA)", localeNames.FindLanguageName("en-US"));

Expand All @@ -49,7 +49,7 @@ public void LocaleNames_Find_language_name_for_current_culture()
[TestMethod]
public void LocaleNames_Find_language_name_for_language_code()
{
var localeNames = LocaleNames.ForLanguageCode("en-US");
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

Assert.AreEqual("German", localeNames.FindLanguageName("de"));

Expand All @@ -65,7 +65,7 @@ public void LocaleNames_Find_language_name_for_language_code()
[TestMethod]
public void LocaleNames_Find_language_name_for_unknown_language_code()
{
var localeNames = LocaleNames.ForLanguageCode("unknown-CODE");
var localeNames = LocaleNamesFactory.ForLanguageCode("unknown-CODE");

Assert.AreEqual(null, localeNames.FindLanguageName("de"));
}
Expand Down
6 changes: 3 additions & 3 deletions src/LocaleNames.Test/LocaleNamesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class LocaleNamesTests
[TestMethod]
public void LocaleNames_Is_loading_from_cache()
{
LocaleNames.ClearCache();
var localeName = LocaleNames.ForCultureInfo(new CultureInfo("cs-CZ"));
LocaleNamesFactory.ClearCache();
var localeName = LocaleNamesFactory.ForCultureInfo(new CultureInfo("cs-CZ"));

Assert.IsFalse(localeName.IsFromCache);

localeName = LocaleNames.ForCultureInfo(new CultureInfo("cs-CZ"));
localeName = LocaleNamesFactory.ForCultureInfo(new CultureInfo("cs-CZ"));

Assert.IsTrue(localeName.IsFromCache);
}
Expand Down
16 changes: 10 additions & 6 deletions src/LocaleNames/Enumerations/AltVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ namespace LocaleNames.Enumerations
/// <summary>
/// Provides variants for name.
/// </summary>
[Flags]
public enum AltVariant
{
/// <summary>
/// The none variant.
/// </summary>
None = 0,

/// <summary>
/// The common name variant.
/// </summary>
Common = 0,
Common = 1,

/// <summary>
/// The alternative name variant.
/// </summary>
Alternative = 1,
Alternative = 2,

/// <summary>
/// The short name variant.
/// </summary>
Short = 2,
Short = 4,

/// <summary>
/// The long name variant.
/// </summary>
Long = 4,
Long = 8,

/// <summary>
/// The menu name variant.
/// </summary>
Menu = 8
Menu = 16
}
}
1 change: 1 addition & 0 deletions src/LocaleNames/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class StringExtensions
public static bool IsCountryCodeContinent(this string countryCode)
{
if (string.IsNullOrWhiteSpace(countryCode)) return false;

return int.TryParse(countryCode, out _);
}

Expand Down
Loading

0 comments on commit 46107bb

Please sign in to comment.