<commit_before>import { Helpers } from "./helpers";

export interface ILocalizableOwner {
  getLocale(): string;
  getMarkdownHtml(text: string): string;
  getProcessedText(text: string): string;
}
/**
 * The class represents the string that supports multi-languages and markdown.
 * It uses in all objects where support for multi-languages and markdown is required.
 */
export class LocalizableString {
  public static defaultLocale: string = "default";
  private values = {};
  private htmlValues = {};
  private renderedText: string = null;
  private calculatedText: string = null;
  public onRenderedHtmlCallback: (html: string) => string;
  public onGetTextCallback: (str: string) => string = null;
  public onStrChanged: () => void;
  constructor(
    public owner: ILocalizableOwner,
    public useMarkdown: boolean = false
  ) {
    this.onCreating();
  }
  public get locale() {
    return this.owner ? this.owner.getLocale() : "";
  }
  public strChanged() {
    if (this.renderedText === null) return;
    this.calculatedText = this.calText();
    if (this.renderedText !== this.calculatedText) {
      this.onChanged();
    }
  }
  public get text(): string {
    this.renderedText =
      this.calculatedText !== null ? this.calculatedText : this.calText();
    this.calculatedText = null;
    return this.renderedText;
  }
  private calText(): string {
    var res = this.pureText;
    if (this.owner && this.owner.getProcessedText) {
      res = this.owner.getProcessedText(res);
    }
    if (this.onGetTextCallback) res = this.onGetTextCallback(res);
    return res;<commit_msg>Reduce processorText calling, https://github.com/surveyjs/surveyjs/issues/1128<commit_after>import { Helpers } from "./helpers";

export interface ILocalizableOwner {
  getLocale(): string;
  getMarkdownHtml(text: string): string;
  getProcessedText(text: string): string;
}
/**
 * The class represents the string that supports multi-languages and markdown.
 * It uses in all objects where support for multi-languages and markdown is required.
 */
export class LocalizableString {
  public static defaultLocale: string = "default";
  private values = {};
  private htmlValues = {};
  private renderedText: string = null;
  private calculatedText: string = null;
  public onRenderedHtmlCallback: (html: string) => string;
  public onGetTextCallback: (str: string) => string = null;
  public onStrChanged: () => void;
  constructor(
    public owner: ILocalizableOwner,
    public useMarkdown: boolean = false
  ) {
    this.onCreating();
  }
  public get locale() {
    return this.owner ? this.owner.getLocale() : "";
  }
  public strChanged() {
    if (this.renderedText === null) return;
    this.calculatedText = this.calText();
    if (this.renderedText !== this.calculatedText) {
      this.onChanged();
    }
  }
  public get text(): string {
    this.renderedText =
      this.calculatedText !== null ? this.calculatedText : this.calText();
    this.calculatedText = null;
    return this.renderedText;
  }
  private calText(): string {
    var res = this.pureText;
    if (res && this.owner && this.owner.getProcessedText && res.indexOf('{') > -1) {
      res = this.owner.getProcessedText(res);
    }
    if (this.onGetTextCallback) res = this.onGetTextCallback(res);
    return res;
{'fraction_non_alphanumeric': 0.12077882567690904, 'fraction_numerical': 0.0015211439002129601, 'mean_word_length': 3.7173601147776183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85787', 'n_tokens_mistral': 988, 'n_tokens_neox': 964, 'n_words': 263}