参数使用中文会有编译后是乱码 The parameters are in Chinese and will be garbled after compilation.
我使用了最简单的一个示例,使用中文的参数名,再AE中打开是乱码 I used the simplest example, using Chinese parameter names, but they appear as gibberish when opened in AE.
We probably need an minimum example and a bit more info. I.e. are you on Windows or macOS, does the issue manifest on both platforms etc.
我只用中文win11 系统,AE2024 中文系统,使用的是示例中简单示例,里面有一个不透明度,我改成了中文,编译后在ae中是乱码,我克隆代码到了本地,然后尝试做了些修改,发现还是有很大问题,比如AE在英文状态下,中文又会乱码, 下面是我修改后的代码,编译后解决了我当前系统中的乱码问题
I only use the Chinese win11 system and the AE2024 Chinese system. I used the simple example in the example, which had an opacity setting. I changed it to Chinese, but after compiling, it was gibberish in AE. I cloned the code to my local machine and tried to make some changes, but there were still many problems, such as AE displaying gibberish in Chinese when in English mode. Here is the modified code that solved the encoding issues in my current system after compilation.
pub fn set_name(&mut self, name: &str) {
#[cfg(target_os = "windows")]
{
use encoding::all::GBK;
use encoding::{EncoderTrap, Encoding};
const MAX_NAME_LEN: usize = 32;
// 将 UTF-8 字符串转换为 GB2312(或 GBK 编码)
let encoded = GBK
.encode(name, EncoderTrap::Strict)
.unwrap_or_else(|_| vec![]);
// 将 Vec<u8> 转换为 Vec<i8>, 同时确保值在 i8 的有效范围内
let encoded_i8: Vec<i8> = encoded.into_iter().map(|x| x as i8).collect();
let copy_len = MAX_NAME_LEN.min(encoded_i8.len());
assert!(copy_len <= MAX_NAME_LEN);
// 拷贝到目标数组
self.param_def.name[0..copy_len].copy_from_slice(&encoded_i8[0..copy_len]);
// 确保 '\0' 结尾
if copy_len < MAX_NAME_LEN {
self.param_def.name[copy_len] = 0;
}
}
#[cfg(target_os = "macos")]
{
let name_cstr = CString::new(name).unwrap();
let name_slice = name_cstr.to_bytes_with_nul();
assert!(name_slice.len() <= 32);
self.param_def.name[0..name_slice.len()]
.copy_from_slice(unsafe { std::mem::transmute(name_slice) });
}
}
@loyoi could you please check if Chinese parameter names are handled correctly in the latest git master version?