Skip to content

DnnFable/Dnn.Resx.ResxProvider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dnn.Resx.ResxProvider Nuget

A F# Type Provider designed for Fable. It provides typed information on DNN's Resource Files (.resx) during design time and can be loaded with localized texts on runtime with the help of Dnn.Resx

Usage

  • Install Dnn.Resx on your DNN server
  • Install the package Dnn.Resx.ResxProvider from NuGet
  • Add a resource file and generate your model
open Browser.Dom

//ViewResources is the typed representation of the resources for localization
type ViewResources = Dnn.Resx.ResxProvider<"./App_LocalResources/View.resx">

//it can be loaded on runtime using DNN.Resx.
Dnn.Resx.loadResources "~desktopmodules/vendor/modulename/App_LocalResources/View.resx"
|> Promise.iter
    (fun result ->
        let resources = ViewResources result

        // During design time, the items are already available as properties
        console.log resources.``Input.Text``)

What is happening behind the scene?

Fable is going to compile the code from above to this javascript:

import { some } from "./.fable/fable-library.3.1.5/Option.js";

(function () {
    const pr = (() => {
        const res = "~desktopmodules/vendor/modulename/App_LocalResources/View.resx";
        return $.get($.ServicesFramework(0).getServiceRoot('dnn.resx') + 'service/get?strategy=0&resource=' + res);
    })();
    pr.then(((result) => {
        console.log(some(result["Input.Text"]));
    }));
})();

As you see, it uses DNN's old JQuery based ServiceFramework to query the Dnn.Resx service, which returns an object inside a promise. This object is a dictionary with keys pointing to localized texts.

The generated type ViewResources is now completly erased. It already did his job during design and compile time. It was its responsibility to support the developer with intellisense. If the resource gets modified and keys were changed, it would even result into compiler errors.

Inspiration

This type provider was inspired and originally forked from the Fable.JsonProvider

About

A Type Provider for Dnn Resource Files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages