-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
feat(lyrics-plus): add japanese lyrics conversion tool #1990
Conversation
Probably should have the dictionaries included in the same repo |
Alright I included them in the PR now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really amazing work! 😄 Thanks a lot for your contribution.
I just have a few small suggestions regarding this PR.
How about we make it so lyrics plus uses his translation or code or whatever initially with just hotloading but if the user installs the dicts locally via an install script then it uses that method instead? So users who don't need the feature don't need the extra 30mb and the users who often use the feature and don't want the load times can install it |
Co-authored-by: Nam Anh <[email protected]>
Co-authored-by: Nam Anh <[email protected]>
Co-authored-by: ririxi~ <[email protected]>
The dictionaries will now be dynamically loaded if they are not yet present and the conversion menu will show a loading indicator. If the dicts are somehow added to the client in any other way, it will use them instead and skip the downloading step. The download urls are in Translator.js line 6050 |
Could you provide source code for this then which I will upload to repo? |
Do you mean the code of the modified kuroshiro / analyzer bundle that currently sits along the Translator class in Translator.js? I am not quite sure if I understand correctly :/ |
So, you don't have any source-code for this code? We will not be able to update a code then. We can't extract source from webpack compiled code. |
Oh yea my bad! I added the unminified code and split it into kuromoji.js and kuroshiro.js If wanted we can move them to the separate repo? |
Revert this commit please. I didn't mean unminified code but source code of it. This is still bundled by webpack which is not a source code |
This reverts commit 2d67f8e.
I am afraid I cant provide you with what you are looking for in that case |
We are asking for the original code in which this was compiled to, if that clarifies anything for you. Currently what you have committed here is the minified/compiled code from a Webpack build process, of which we cannot inspect, verify and maintain its functionality. |
I will have to get to work on the files from the Kuroshiro repo again, because I was as naive as to modify the compiled code from npm directly and thus am not and never haven been in the possession of the uncompiled code. |
Is there a possibility of bundling the translate function within Spicetify? So maybe it can be used in other extensions and custom apps, etc? |
The extension will be released as a standalone package so feel free to use that instead. We have no plans to bundle it into the CLI, mostly because it has a very small use case, scope of usage and is 10 times larger the CLI itself. |
Yeah, but the problem is importing modules in the extensions and making it work with marketplace, unless that was fixed? |
That would be discussed on the Marketplace side of development. You can always choose to opt out on having users install via Marketplace and do it locally instead. We are also planning to make an option for developers to redirect users to their repository's Readme instead of installing by default on Marketplace (spicetify/marketplace#346) Either way, we are not forcing users to increase their installation package size by tenfold for a feature that has probably around 1-2% of the userbase using it. |
In case it helps, I've also been trying to integrate Kuroshiro in a spicetify extension without having to download the dictionary files locally, and got it to work without having to host the files in a repo. You can directly get the dictionary files from npm. The repo is private for now so I can't link the file but here is the code I'm using (the extension is built with spicetify creator): import Kuroshiro from 'kuroshiro';
import KuromojiAnalyzer from '../../node_modules/kuroshiro-analyzer-kuromoji/dist/kuroshiro-analyzer-kuromoji.min.js';
type ExtendedXMLHttpRequest = XMLHttpRequest & {
patched_open: (method: string, url: string) => void;
};
const dictPath = 'https://cdn.jsdelivr.net/npm/[email protected]/dict';
const dictPathWithoutDoubleSlash =
'https:/cdn.jsdelivr.net/npm/[email protected]/dict';
/**
* Fix an issue with kuromoji when loading dict from external urls
* See: https://github.com/takuyaa/kuromoji.js/issues/37
* Adapted from: https://github.com/mobilusoss/textlint-browser-runner/pull/7
*/
export function applyKuromojiFix(): void {
(XMLHttpRequest.prototype as ExtendedXMLHttpRequest).patched_open =
XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method: string, url: string) {
if (url.indexOf(dictPathWithoutDoubleSlash) === 0) {
(this as ExtendedXMLHttpRequest).patched_open(
method,
url.replace(dictPathWithoutDoubleSlash, dictPath)
);
} else {
(this as ExtendedXMLHttpRequest).patched_open(method, url);
}
};
}
export async function createKuroshiro(): Promise<Kuroshiro> {
applyKuromojiFix();
const kuroshiro: Kuroshiro = new Kuroshiro();
const analyzer: KuromojiAnalyzer = new KuromojiAnalyzer({
dictPath: dictPath,
});
await kuroshiro.init(analyzer);
return kuroshiro;
} |
Thank you for your contribution and this fantastic extension. I'd like to know if we can convert Romanji further into English. |
i really hope this isnt abandoned lol |
I think I got it to work by loading kuroshiro, kuromoji and the dictionary files via JSDeliver directly from npm using the XMLHttp fix similar to the one suggested by Pithaya. If you approve these changes I will look into resolving the merge conflicts I have also seen a lot request for supporting romanization of more languages like Korean or Russian |
It's okay by me, @41pha1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This adds the functionality of switching between different display modes for Japanese lyrics.