Skip to content

Feature request: Additional language string regexes #8

@FMCorz

Description

@FMCorz

It would be useful (to me) if we could configure additional language string regexes as some of my custom implementations aren't detected, and the strings are reported as unused when they actually are.

Why do I have custom language string calls? I write TypeScript/React code which is then transpiled in AMD code. Under the hood they use the regular Moodle language string modules but they aren't detected by the extension.

If regexes could be configured, it might be useful to restrict their scopes to certain components and/or file types to avoid performance issues. Although, having regexes to begin with would be ideal. To make things more annoying, I typically set the default component of the function call as the plugin I wrote these in.

I note that I am suggesting regexes because I understand that my use case isn't common.

React hooks example:

// Usage.
const filterStr = useString("filterellipsis");
const getStrFn = useStrings(["deletecondition", "editcondition", "ruleadded"]);
const deleteConditionStr = getStrFn('deletecondition');

// Hook signature.
const useString = (id: string, component: string = "block_xp", a?: any): string;
const useStrings = <T extends string>(ids: T[], component: string = "block_xp"): ((id: T, a?: any) => string);

React component example:

// Usage.
<Str id="deletecondition" />

// Component.
const Str = ({ id, component = "block_xp", a }: { id: string; component?: string; a?: any }) => {
  const str = useString(id, component, a);
  return <>{str || "​"}</>;
};

Sources/examples:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions