spreed icon indicating copy to clipboard operation
spreed copied to clipboard

fix(l10n): directly import translate functions to the components

Open Antreesy opened this issue 1 year ago • 2 comments

☑️ Resolves

  • Required for #12362

Scripted with:

<?php
function injectStrings($directory) {
	$iterator = new RecursiveIteratorIterator(
		new RecursiveDirectoryIterator($directory),
		RecursiveIteratorIterator::SELF_FIRST
	);

	foreach ($iterator as $file) {
		if ($file->isFile()) {
			$filePath = $file->getPathname();
			$contents = file_get_contents($filePath);

			if (strpos($contents, "t('spreed'") !== false && strpos($contents, "from '@nextcloud/l10n'") === false) {
				$newContents = preg_replace(
					'/<script>/',
					"<script>\nimport { t } from '@nextcloud/l10n'",
					$contents
				);

				$newContents = preg_replace(
					'/methods:\s*\{/',
					"methods: {\n		t,",
					$newContents
				);

				file_put_contents($filePath, $newContents);
				echo "Injected strings in $filePath\n";
			}
		}
	}
}

// Example usage
injectStrings('.');
?>

🖌️ UI Checklist

🚧 Tasks

  • [ ] ...

🏁 Checklist

  • [ ] 🌏 Tested with Chrome, Firefox and Safari or should not be risky to browser differences
  • [ ] 🖥️ Tested with Desktop client or should not be risky for it
  • [ ] 🖌️ Design was reviewed, approved or inspired by the design team
  • [ ] ⛑️ Tests are included or not possible
  • [ ] 📗 User documentation in https://github.com/nextcloud/documentation/tree/master/user_manual/talk has been updated or is not required

Antreesy avatar May 17 '24 11:05 Antreesy

Shall we do it in main?

ShGKme avatar May 17 '24 12:05 ShGKme

Shall we do it in main?

There's a lot of files conflicts, so I'd keep it as a next version, what do you think?

Antreesy avatar May 17 '24 12:05 Antreesy

For history, using global t wasn't good because:

  • It's indeterminate. There is no guarantee, window.t is the same version as installed @nextcloud/l10n. Different modules may use different versions. Same with Vue.prototype.t in Vue 2.
  • No way to check if in this context t is defined. Either error from ESLint/TS everywhere, or missing actual errors. We have problems from that in @nextcloud/vue time to time

ShGKme avatar Jun 14 '24 12:06 ShGKme