feat: Add project-specific naming convention in LocalizeItAction

Refactored convertKeyToNamingCase method to include project-specific naming conventions. Now, it adapts to the naming convention specified in the project settings. This change enhances flexibility by catering to individual project preferences.
This commit is contained in:
JPilson 2024-04-18 21:03:15 +02:00
parent b7b3563080
commit f933ea91eb

View File

@ -11,6 +11,7 @@ import com.intellij.openapi.project.Project;
import de.marhali.easyi18n.dialog.AddDialog;
import de.marhali.easyi18n.model.KeyPath;
import de.marhali.easyi18n.settings.NamingConvention;
import de.marhali.easyi18n.settings.ProjectSettingsService;
import de.marhali.easyi18n.util.DocumentUtil;
@ -48,7 +49,7 @@ class LocalizeItAction extends AnAction {
throw new RuntimeException("Project is null!");
}
AddDialog dialog = new AddDialog(project, new KeyPath(convertKeyToNamingCase(text, true)), text, (key) -> replaceSelectedText(project, editor, key));
AddDialog dialog = new AddDialog(project, new KeyPath(convertKeyToNamingCase(text, project)), text, (key) -> replaceSelectedText(project, editor, key));
dialog.showAndHandle();
}
@ -82,9 +83,12 @@ class LocalizeItAction extends AnAction {
return flavorTemplate + "(\"" + key + "\")";
}
private String convertKeyToNamingCase(String key, boolean camelCase) {
private String convertKeyToNamingCase(String key,Project project) {
String newKey = key.toLowerCase();
return camelCase ? convertKeyToCamelCase(newKey) : convertKeyToSnakeCase(newKey);
newKey = newKey.replaceAll("\\s+", "_");
NamingConvention namingConvention = ProjectSettingsService.get(project).getState().getCaseFormat();
return (namingConvention == NamingConvention.CAMEL_CASE) ? convertKeyToCamelCase(newKey) : convertKeyToSnakeCase(newKey);
}
private String convertKeyToCamelCase(String key) {