lmscloud-io / mdlcode-docs

5 stars 2 forks source link

Feature request: Additional language string regexes #8

Open FMCorz opened 3 months ago

FMCorz commented 3 months ago

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:

lmscloud-io commented 3 months ago

Hi Fred, There are already some directives you can add, see https://mdlcode.dev/docs/directives

However I don't think MDLCode will index/analyse the ts/tsx files at all. And also I'm not sure if the library I use to parse JS files will even work with typescript, I would need to bring in a new library, add allowed paths, etc.

I'll look at your plugin and see if it can be done quickly

FMCorz commented 3 months ago

Thanks, I'll have a look at directives.