Skip to content

BaseJsonTextsGenerator class

namespace: Serenity.Localization   assembly: Serenity.Extensions

Regenerates the JSON texts of the projects of an application: the base template of the texts of each project, *.texts.__.json, from the local texts in its assembly, and the other languages from it, keeping the translations that are there. An application derives from this class and says which feature projects it has, see GetFeatureTargets, and runs it from the command line, e.g. with json-texts, see RunIf, or from a module initializer, so that a new project can have the texts of its own.

public abstract class BaseJsonTextsGenerator
parameter description
projectFolder The folder of the project of the application, or null for the one that the application is run from, which is the project folder of it when it is run from there, e.g. with dotnet run --project YourProject.Web, or from its folder with dotnet YourProject.Web.dll json-texts.

Public Members

name description
ProjectFolder { get; } Gets the folder of the project of the application, e.g. "…/YourProject.Web", which the application is run from by default, as its texts are in it.
virtual Run() Regenerates the json texts of the projects of the application, which are the ones that GetFeatureTargets and GetSiteTarget return, in the folder of the project that it is run from, see EnsureProjectFolder.
virtual RunIf(…) Runs the generator when the first argument is Command, as the dynamic data generator does for its own command, so that the application can exit with the code that it returns.
const Command The command that runs the generator, which an application passes to RunIf.
const TemplateComment The comment that the template of a project starts with, which tells that nothing else in it is to be changed.
static UpdateOutOfDateTranslations(…) Keeps the list of the translations that are out of date, as the text of their key changed after they were made, in a file next to the texts of the project, which is ignored at runtime like the template. A translation is kept in the language files as it is, as an old one is still better than the one of the template, and it is listed with the text it was made for until someone changes it. An entry is removed when the translation is changed or emptied, the text is back to the old one, or the key is gone, and the file is removed when nothing is left.

Protected Members

name description
BaseJsonTextsGenerator(…) Regenerates the JSON texts of the projects of an application: the base template of the texts of each project, *.texts.__.json, from the local texts in its assembly, and the other languages from it, keeping the translations that are there. An application derives from this class and says which feature projects it has, see GetFeatureTargets, and runs it from the command line, e.g. with json-texts, see RunIf, or from a module initializer, so that a new project can have the texts of its own.
virtual EnsureProjectFolder() Checks that the folder that the application is run from is the folder of its project, which the generator assumes, as it writes the texts of the application there, and throws when it is not, rather than write a folder of texts somewhere else.
virtual GetFeatureTargets() Gets the projects of the features that the application uses, whose texts are written along with the ones of the application itself, before them, so that a text that the application has as well is its own. An application that has no such projects, e.g. one that uses them as packages, which have their templates in them, has none.
virtual GetSiteTarget() Gets the project of the application itself, which is the one that the generator is in, and whose texts are written to its "texts/resources" folder, as "site.texts", e.g. "site.texts.__.json", which is what the texts of an application are translated from.
virtual GetUserTargets() Gets the folders of the texts that an application has in it, e.g. the ones that its users add through the translation page, which are read for the translations of a key, but are not written by the generator. It is the "App_Data/texts" folder of the project of the application, which is where the translation page puts them.
virtual ShouldResetTranslation(…) Whether a translation of a key is to be reset, as it can not be what the text of the key needs, e.g. one that lost the placeholders of it, which would show a text without them.
class TextsTarget A project whose texts are in a folder of the source tree, e.g. the web project itself and the projects of the features that it uses.

Remarks

The template of a project is what its texts are translated from, and what the constants of its text keys are written from, see the TextKeys of a project, so that a key that the code uses is a key that the application has. A project that has no template, e.g. one that is not generated with this one, is not a matter for the texts of the application, as the ones of another project are not, and it is skipped.

Initializes a new instance of the BaseJsonTextsGenerator class.

See Also