-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the optimal way to load strings using Typescript? #1053
Comments
Maybe we can create a TypeScript type that means: an object that can have any keys, but the values are all |
I tried this pattern in Gravity and Orbits, and it works great in the sim code, but fails during builds import gravityAndOrbitsStrings from './gravityAndOrbitsStrings.js';
type GravityAndOrbitsStrings = {
moonMass: string,
planetMass: string,
satelliteMass: string,
starMass: string,
toScale: string,
model: string
gravityForce: string,
grid: string,
mass: string,
measuringTape: string,
path: string,
velocity: string,
moon: string,
planet: string,
satellite: string,
star: string,
clear: string,
v: string,
returnObjects: string,
earthMasses: string,
earthMass: string,
// pattern[ '0value' ][ '1units' ]:string,
pattern: any,
thousandEarthMasses: string,
billionBillionSpaceStationMasses: string,
spaceStationMass: string,
gravity: string,
on: string,
off: string,
'gravity-and-orbits': any,
kilometers: string
};
export default gravityAndOrbitsStrings as GravityAndOrbitsStrings; with this error:
It was working fine with *.js when we had |
In phetsims/bending-light#401 I found that adding a d.ts file for the strings makes it easy to say "the strings have a string key and a string value". Though not very strict, it is a convenient way to get things working without repeating ourselves. I'll commit the same pattern for gravity and orbits. |
We now have type declarations automatically generated for our strings, closing. |
If we move to Typescript, is there a better way to render/load the strings than we do now? See #1047
Brainstorming some ideas:
I'm not too familiar with the string plugin, so not sure what's possible or what the constraints are. Do we ever need to be able to load more than one language at runtime?
The text was updated successfully, but these errors were encountered: