Skip to content

Commit

Permalink
moved opti to main repo
Browse files Browse the repository at this point in the history
set v8.2.2
  • Loading branch information
Valdis Iljuconoks committed Nov 15, 2024
1 parent 0dfe67d commit 4c0d66e
Show file tree
Hide file tree
Showing 453 changed files with 32,393 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public class Startup
```



Also, you can refer to [sample app in GitHub](https://github.com/valdisiljuconoks/localization-provider-core/tree/master/tests/DbLocalizationProvider.Core.AspNetSample) for some more hints if needed.

### More Detailed Help
Expand All @@ -115,6 +114,14 @@ Also, you can refer to [sample app in GitHub](https://github.com/valdisiljuconok
* [Localizing View Model (with DataAnnotations attributes)](aspnetcore/docs/localizing-viewmodel-netcore.md)
* [Localizing Client-side](aspnetcore/docs/client-side-provider-netcore.md)


## Getting Started - Optimizely CMS/Commerce

* [Working with Resources (Optimizely)](optimizely/docs/working-with-resources-epi.md)
* [Optimizely Frontend Localization](optimizely/docs/jsresourcehandler-epi.md)
* [Optimizely Xml File Migration](optimizely/docs/xml-migration-epi.md)


## Working with DbLocalizationProvider Stuff

* [Localized Resource Types](common/docs/resource-types.md)
Expand All @@ -141,10 +148,6 @@ Also, you can refer to [sample app in GitHub](https://github.com/valdisiljuconok

Please read more in [this blog post](https://tech-fellow.eu/2022/01/23/dblocalizationprovider-for-optimizely/)!

## Upgrade to v7.x?

Please read more details in [this blog post](https://tech-fellow.eu/2022/01/23/dblocalizationprovider-for-optimizely/)!


# More Info

Expand Down
199 changes: 199 additions & 0 deletions optimizely/DbLocalizationProvider.Episerver.sln

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions optimizely/DbLocalizationProvider.Episerver.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Opti/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Optimizely/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xliff/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
19 changes: 19 additions & 0 deletions optimizely/build-packages.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cd .\.nuget

# episerver libraries

cd .\..\src\DbLocalizationProvider.EPiServer\
dotnet build -c Release
dotnet pack -c Release
copy .\bin\Release\DbLocalizationProvider.EPiServer.*.nupkg .\..\..\.nuget\
copy .\bin\Release\DbLocalizationProvider.EPiServer.*.snupkg .\..\..\.nuget\
cd .\..\..\.nuget\

cd .\..\src\DbLocalizationProvider.AdminUI.EPiServer\
dotnet build -c Release
dotnet pack -c Release
copy .\bin\Release\DbLocalizationProvider.AdminUI.EPiServer.*.nupkg .\..\..\.nuget\
copy .\bin\Release\DbLocalizationProvider.AdminUI.EPiServer.*.snupkg .\..\..\.nuget\
cd .\..\..\.nuget\

cd ..
41 changes: 41 additions & 0 deletions optimizely/docs/adminui-epi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Administration UI (EPiServer)

Administration UI is available form top menu under `CMS > Localization`.

## Customize AdminUI

There are couple options available for you to customize AdminUI. Everything is done via `UiConfigurationContext.Setup` method - similar as for localization provider core packages.

For example setting few properties for AdminUI:

```csharp
[InitializableModule]
[ModuleDependency(typeof(InitializationModule))]
public class InitLocalization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
UiConfigurationContext.Setup(_ =>
{
_.DefaultView = ResourceListView.Tree;
_.TreeViewExpandedByDefault = true;
_.ShowInvariantCulture = true;
_.DisableView(ResourceListView.Table);
});
}

public void Uninitialize(InitializationEngine context)
{
}
}
```

## Export & Import - View Diff

Once upon a time I got sick of merging and importing new resources from staging environment (with adjusted translations by editors) into production database where on the other hand editors already made changes to existing resources. Up till now import process only supported *partial import* or *full import*. Partial import was dealing with only new resources (those ones that were not in target database), however full import - on the other hand - was used to flush everything and import stuff from exported file. Kinda worked, but it was v0.1 of this export/import component. Pretty green.

Updates to this story was one of the main focus for this upcoming version. Eventually if you are importing resources from other environment, now your import experience might look like this:

![](adminui-import.png)

To share the code would be overkill here in this post. Better sit back and [relax watching](https://vimeo.com/205294678) import in action. Enjoy!
Binary file added optimizely/docs/adminui-import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 131 additions & 0 deletions optimizely/docs/getting-started-epi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Getting Started (Optimizely)

## What is LocalzationProvider for Optimizely?

LocalizationProvider project is an attempt to improve Optimizely built-in localization provider originally based on collection of Xml files.

Aside from features for .NET apps Optimizely integration gives following additional features:
* Database driven localization provider for Optimizely projects
* Administration UI for editors to change or add new translations for required languages
* Possibility to add new localized translations while adding new language to the Optimizely site without involving the developer
* Easy migration tool from built-in default Xml files to your Optimizely database

## Getting Started

Localization Provider for Optimizely consists from few components:

* `DbLocalizationProvider.EPiServer` - core package for Optimizely integration giving you all necessary extension methods for working with resources or models in Optimizely environment.
* `DbLocalizationProvider.AdminUI.EPiServer` - administrator user interface for editors and administrators to overview resources, manage translations, import / export and do other tasks.
* `LocalizationProvider.MigrationTool` - tool to help migrate from Xml language files (default Optimizely localization approach) to database driven provider.


### Installing Localization Provider

Installation nowadays can't be more simpler as just adding NuGet package(s). Add Optimizely integration package trogether with AdminUI:

```powershell
> dotnet add package DbLocalizationProvider.EPiServer
> dotnet add package DbLocalizationProvider.AdminUI.Optimizely
```

And also you might need to install SQL Server storage implementation (if you are using default Optimizely database to store resources):

```powershell
> dotnet add package LocalizationProvider.Storage.SqlServer
```

## Setup & Configuration

### Adding Provider to the Application
After installing packages you need to configure few things.

Adding it to the service collection:

```csharp
public void ConfigureServices(IServiceCollection services)
{
services
.AddDbLocalizationProvider(ctx =>
{
// now you can set different options via configuration context (`ctx`)
})
.AddOptimizely(); // add Optimizely integration
}
```

Use provider in the application:

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDbLocalizationProvider();
}
```

### Adding Provider AdminUI to the Application

If you need AdminUI this requires additional setup.
Adding it to the service collection:

```csharp
public void ConfigureServices(IServiceCollection services)
{
services
.AddDbLocalizationProviderAdminUI(ctx =>
{
// now you can set different options via configuration context (`ctx`)
})
.AddOptimizelyAdminUI() // add Optimizely integration (adds menu items and stuff)
.AddCsvSupport() // you can also add additional export formats if needed
.AddXliffSupport();
}
```

Use localization provider in the application (make sure you call also `UseStaticFiles()`):

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseStaticFiles();

app.UseAuthentication();
app.UseAuthorization();

app.UseDbLocalizationProvider();
app.UseDbLocalizationProviderAdminUI();

app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapDbLocalizationAdminUI();
});
}
```

### Configure to use SQL Server
In order to get localization provider to work properly - you might need to point to Optimizely database (where resources will be stored).

This is done by configuring provider to use SQL Server storage implementation:

```csharp
private readonly IConfiguration _configuration;

public Startup(IConfiguration configuration)
{
_configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
services
.AddDbLocalizationProvider(ctx =>
{
ctx.UseSqlServer(_configuration.GetConnectionString("EPiServerDB"));
})
.AddOptimizely();
}
```

## Other Configuration Options

For list of available startup configuration options [visit this page](https://github.com/valdisiljuconoks/localization-provider-core/blob/master/docs/getting-started-netcore.md#configure-services).
120 changes: 120 additions & 0 deletions optimizely/docs/jsresourcehandler-epi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Javascript Resource Handler

Along with other smaller bug fixes, database-driven localization provider for EPiServer got closer to front-end. We joined forces together with my old pal and friend [Arve Systad](https://github.com/ArveSystad) and made it possible to add translations to client side resources as well.

## Setup
So setup for the client-side resource localization with help of DbLocalizationProvider plugin is more or less straight forward. You will need to install `DbLocalizationProvider.EPiServer.JsResourceHandler` package from [EPiServer feed](http://nuget.episerver.com/en/?search=localization) and add corresponding `<script>` include in your markup file to fetch translations from the server:

```
@Html.GetTranslations(typeof(...{type of the class holding resources}...))
```

or

```
<script src="/jsl10n/{beginning-of-resource-keys}">
```

You have to specify beginning of resource keys to fetch those from the server.

### Sample Resources
For instance you have following resources defined in your code:

```csharp
namespace MyProject
{
[LocalizedResource]
public class MyResources
{
public static string FirstProperty => "One";
public static string SecondProperty => "Two";
}

[LocalizedResource]
public class AlternativeResources
{
public static string ThirdProperty => "Three";
public static string FothProperty => "Four";
}
}
```

Following resources will be registered:

```
MyProject.MyResources.FirstProperty
MyProject.MyResources.SecondProperty
MyProject.AlternativeResources.ThirdProperty
MyProject.AlternativeResources.FothProperty
```

If we include following code:

```
@Html.GetTranslations(typeof(MyProject))
```

or following `<script>` element:

```html
<script src="/jsl10n/MyProject"></script>
```

All resources from both classes will be retrieved:

<img src="http://blog.tech-fellow.net/content/images/2017/03/2017-03-19_23-54-26.png"/>

Resources retrieved in this way are accessible via `jsl10n` variable:

```html
<script type="text/javascript">
alert(window.jsl10n.MyProject.AlternativeResources.ThirdProperty);
</script>
```

**NB!** Notice that naming notation of the resource is exactly the same as it's on the server-side. This notation should reduce confusion and make is less problematic to switch from server-side code to front-end, and vice versa.

### Aliases
Sometimes it's required to split resources into different groups and have access to them separately. Also the same problem will occur when you would like to retrieve resources from two different namespaces in single page. Therefore aliasing particular group of resources might come handy. You have to specify `alias` query string parameter:

```html
<script src="/jsl10n/MyProject.MyResources?alias=m"></script>
<script src="/jsl10n/MyProject.AlternativeResources?alias=ar"></script>

<script type="text/javascript">
alert(window.m.MyProject.MyResources.FirstProperty);
alert(window.ar.MyProject.AlternativeResources.ForthProperty);
</script>
```

## Explicit Translation Culture
Sometimes it's also necessary to fetch translations for other language. This is possible specifying `lang` query parameter.

```
@Html.GetTranslations(typeof(MyProject), language: "no")
```

or

```html
<script src="/jsl10n/MyProject?lang=no"></script>
```

**Note:** Those resources that do not have translation in requested language will not be emitted in resulting `json` response.

## Translations Only in JSON
If you need to retrieve translations only in JSON format (without any `window` thingies) then you can just send simple XHR request to the endpoint:

```
$.ajax({
url: '/jsl10n/MyProject.MyResources',
method: 'GET'
}).done(function (data) {
...
});
```

Localization provider is checking one of headers - `Accept: application/json` or `X-Requested-With: XMLHttpRequest`.

Or you can append `?json=true` to the query string (e.g. `/jsl10n/MyProject.MyResources?json=true`) to get the same effect.
Loading

0 comments on commit 4c0d66e

Please sign in to comment.